Just tried, and it works perfectly
php artisan make:controller frontend/SomeController
frontend is the name of your folder.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How do i create a controller using the Artisan make command inside a folder in the Controller folder ie app\Http\Controller\Mobile.
Just tried, and it works perfectly
php artisan make:controller frontend/SomeController
frontend is the name of your folder.
Isn't it
php artisan make:controller Mobile/MobileController
It was first not possible.. Learned something today ;)
thanks bashy and rashid I have been trying with a backslash \ instead of /
@gustav Quote the namespace, i.e.
php artisan make:controller "Mobile\SomeController"
Just escape the backslash:
php artisan make:controller Mobile\\SomeController
I used the following on route.
Route::get('login', 'DashboardController@index');
also i check it create the admin folder. i try the group after creating the controller but it does not work for me
Route::group(['prefix' => 'adminPanel'], function () {
Route::get('login', 'DashboardController@index');
});
i also try
composer dump-autoload
whats is wrong with my code i used php artisan to crate controller even by command
php artisan make:controller adminPanel/DashboardController
i am using laravel 5.1 i also tried
php artisan route:scan
it shows no command found.
@gustav You may try this it will work
php artisan make:controller subDriectory/YourController
php artisan make:controller subDriectory/YourController --plain
You can effectively put controllers where ever you want, even not in http folder. Just ensure proper namespace is used in the routes file.
Your above snippet has the wrong namespace if your controller in in a subfolder.
if you are using Windows
php artisan make:controller "Mobile\SomeController"
if Ubuntu
php artisan make:controller "Mobile/SomeController"
Try php artisan make:controller Mobile/Your_Controller_Name
Use php artisan:make controller Mobile\\SampleController
Then inside the controller make sure to include
use App\Http\Controllers\Controller
@bobbybouwmann but it's possible by this command ( on windows ) :
php artisan make:controller SubFolder/ControllerName
it worked for me on laravel 5.4 .
I know...
It was first not possible.. Learned something today ;)
To create a controller in subfolder :
php artisan make:controller "Test/SampleController"
Then inside SampleController.php :
<?php
namespace App\Http\Controllers\Test;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class SampleController extends Controller
{
public function index()
{
return 'Its working!';
}
}
In routes/Web.php :
Route::get('something', 'Test\SampleControllerextends@index');
Do not use forward slash in your routes/Web.php when defining a route :
// WRONG :
Test/SampleControllerextends@index
Instead use a back slash like :
// Correct :
Test\SampleControllerextends@index
Create your controllers in a subfolder like :
Http
|
|-Controllers
|
|-Test
|
|-FirstController.php
|-SecondController.php
|-ThirdController.php
Now in your routes/Web.php, do not specify folder :
Route::get('/first', 'FirstController@index');
Route::get('/second', 'SecondController@index');
Route::get('/third', 'ThirdController@index');
Then run :
composer dumpautoload
And it should work!
Cheers..
@oooALIooo yes It is possible in windows
In Laravel 8 it's possible to do it like this:
Route::get(
'panel/{panel?}',
[PanelController::class, 'index']
)->name('panel.index');
My PanelController resides outside App\Controllers namespace.
Please or to participate in this conversation.