For example, by running the command php artisan make:controller PostController
it will create the
PostController.php
in app/Htttp/Controllers
And you can access in route:
Route::get('/posts', 'PostController@index')->name('posts.index');
Route::get('/posts/create', 'PostController@create')->name('posts.create');
Route::post('/posts', 'PostController@store')->name('posts.store');
Route::get('/posts/{post}', 'PostController@show')->name('posts.show');
Route::get('/posts/{post}/edit', 'PostController@edit')->name('posts.edit');
Route::put('/posts/{post}', 'PostController@update')->name('posts.update');
Route::delete('/posts/{post}', 'PostController@destroy')->name('posts.destroy');
But in your situation, you are using the custom namespace. For example:
php artisan make:controller Admin\PostController
It will create the new folder inside the Controllers
with file:
app/Http/Controller/Admin/PostController.php
Now you can't access for the route like the previous:
Route::get('/posts', 'PostController@index')->name('posts.index');
Or
Route::resource('/posts', 'PostController');
If you are using custom nameSpaces for the large number of controller, try below method:
Route::group(['namespace' => 'Admin'], function () {
Route::resource('/posts', 'PostController');
});
Or:
Route::group(['namespace' => 'Admin'], function ()
{
Route::get('/posts', 'PostController@index')->name('posts.index');
Route::get('/posts/create', 'PostController@create')->name('posts.create');
Route::post('/posts', 'PostController@store')->name('posts.store');
Route::get('/posts/{post}', 'PostController@show')->name('posts.show');
Route::get('/posts/{post}/edit', 'PostController@edit')->name('posts.edit');
Route::put('/posts/{post}', 'PostController@update')->name('posts.update');
Route::delete('/posts/{post}', 'PostController@destroy')->name('posts.destroy');
});
git status
to show new files – Cody Caughlanfoldername
and only give the controller name is there any difference? – apokryfos