Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Controller Subfolder routing

I'm new to Laravel. To try and keep my app organized I would like to put my controllers into subfolders of the controller folder.

controllers\ ---- folder1 ---- folder2 

I tried to route to a controller, but laravel doesn't find it.

Route::get('/product/dashboard', 'folder1.MakeDashboardController@showDashboard'); 

What am I doing wrong?

like image 224
Tino Avatar asked Sep 17 '13 12:09

Tino


1 Answers

For Laravel 5.3 above:

php artisan make:controller test/TestController 

This will create the test folder if it does not exist, then creates TestController inside.

TestController will look like this:

<?php namespace App\Http\Controllers\test;  use Illuminate\Http\Request; use App\Http\Controllers\Controller;  class TestController extends Controller {     public function getTest()     {         return "Yes";     } } 

You can then register your route this way:

Route::get('/test','test\TestController@getTest'); 
like image 181
Ja22 Avatar answered Oct 02 '22 11:10

Ja22