Skip to main content
added 268 characters in body
Source Link
Coloured Panda
  • 3.5k
  • 3
  • 23
  • 33

Although laravel is magic at times, it only works if you stick the the default configuration and conventions.

You can place your controllers anywhere (heck, even load from a database and eval them) but you have to change the configuration accordingly.

I suspect you have the wrong namespace configured in RouteServiceProvider. By default it is App\Http\Controllers.

Changing default folder

If all your controllers will be in the same folder, change it to App\Student\Controllers and forget about it should work.

class RouteServiceProvider extends ServiceProvider { // ... protected $namespace = 'App\Student\Controllers'; // ... } 

Multiple modules

If you want to have multiple modules, then change your RotueServiceProvider namespace config to App and in route files use Student\Controllers\StudentController@list

class RouteServiceProvider extends ServiceProvider { // ... protected $namespace = 'App'; // ... } Route::get('/list', 'Student\Controllers\StudentController@list'); 

Although laravel is magic at times, it only works if you stick the the default configuration and conventions.

You can place your controllers anywhere (heck, even load from a database and eval them) but you have to change the configuration accordingly.

I suspect you have the wrong namespace configured in RouteServiceProvider. By default it is App\Http\Controllers.

If all your controllers will be in the same folder, change it to App\Student\Controllers and it should work.

class RouteServiceProvider extends ServiceProvider { // ... protected $namespace = 'App\Student\Controllers'; // ... } 

If you want to have multiple modules, then change your RotueServiceProvider namespace config to App and in route files use Student\Controllers\StudentController@list

Although laravel is magic at times, it only works if you stick the the default configuration and conventions.

You can place your controllers anywhere (heck, even load from a database and eval them) but you have to change the configuration accordingly.

I suspect you have the wrong namespace configured in RouteServiceProvider. By default it is App\Http\Controllers.

Changing default folder

If all your controllers will be in the same folder, change it to App\Student\Controllers and forget about it.

class RouteServiceProvider extends ServiceProvider { // ... protected $namespace = 'App\Student\Controllers'; // ... } 

Multiple modules

If you want to have multiple modules, then change your RotueServiceProvider namespace config to App and in route files use Student\Controllers\StudentController@list

class RouteServiceProvider extends ServiceProvider { // ... protected $namespace = 'App'; // ... } Route::get('/list', 'Student\Controllers\StudentController@list'); 
Source Link
Coloured Panda
  • 3.5k
  • 3
  • 23
  • 33

Although laravel is magic at times, it only works if you stick the the default configuration and conventions.

You can place your controllers anywhere (heck, even load from a database and eval them) but you have to change the configuration accordingly.

I suspect you have the wrong namespace configured in RouteServiceProvider. By default it is App\Http\Controllers.

If all your controllers will be in the same folder, change it to App\Student\Controllers and it should work.

class RouteServiceProvider extends ServiceProvider { // ... protected $namespace = 'App\Student\Controllers'; // ... } 

If you want to have multiple modules, then change your RotueServiceProvider namespace config to App and in route files use Student\Controllers\StudentController@list