1
votes

I'm working on Laravel 5.7 project and I'm trying to create a controller with this name AdminController with this command "php artisan make:controller foldername\AdminController" then I give it a route like this Route::get('/admin','AdminController@login');

the thing is I can't find the AdminController in my project folders? I searched in App/Http/Controller also it's not there?

2
Are you using git? You could run git status to show new filesCody Caughlan
no, I'm not using git!!Alaa A. Al Sa'edy
Can you show us your folder structure?Laurens
If you don't use foldername and only give the controller name is there any difference?apokryfos
Folder structure ibb.co/nMZGy3nAlaa A. Al Sa'edy

2 Answers

1
votes

You put your controller in a folder so you must call this folder name in Route and in namespace of controller.

Try "php artisan make:controller foldername/AdminController"

Your route must be: Route::get('/admin','foldername\AdminController@login')

And your controller namespace is namespace App/Http/Controller/foldername

0
votes

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');
});