0
votes

I am using "artem-schander/l5-modular": "dev-master" for laravel moduler development.

For example i create an Admin module.

Folder structure is App/Modules/Admin.

So controller related to Admin modules placed under App/Modules/Admin/Controllers/ directory.

All routes related to Admin module are placed in App/Modules/Admin/routes.php file.

Here how it looks

Route::group(array('module' => 'Admin', 'middleware' => ['web'],'namespace' => 'App\Modules\Admin\Controllers'), function() {

    Route::resource('admin', 'AdminController');

}); 

All view files related to admin module placed in App/Modules/Admin/Views folder.

I am trying to access Admin's index view using this route

Route::get('/', 'AdminController@index');

This route is place in laravel default routes.php file.

and when i browse ,I am getting this error

Class App\Http\Controllers\AdminController does not exist

From this i understood , laravel looking AdminController in its default path.

How can i overcome this challenge ?

2

2 Answers

1
votes

You can access a controller by full qualified namespace if it is not in default path.

Try:

Route::resource('admin', '\App\Modules\Admin\Controllers\AdminController');
0
votes

I have found two way to do it.

First Option

Changing the $namespace in RouteServiceProvider.php .

For me

private $namespace='\App\Modules';

So for Admin module i can use route as

Route::get('/', 'Admin\Controllers\AdminController@index');

I think this is bad idea to change Laravel's default value.

Second Option

Providing full path of the Controller.

So route would be like this

Route::get('/','\App\Modules\Admin\Controllers\AdminController@index');