Routing in the Laravel Module

I created the module in Laravel 5 ie at the same level as the application folder, as part of creating the HMVC structure in Laravel. I have two modules in the module folder, one of which is the project folder and the other is the form folder. Now I got the controller, model and view inside these folders.

Click here to view the folder structure.

Now when I try to access my controller, for example

Route::controller('project/dashboard', 'ProjectController@index'); 

I get an error

 ReflectionException in ControllerInspector.php line 35: Class ProjectController does not exist 

I would like to learn about controller routing in a modular structure in Laravel.

0
laravel-5
Nov 30 '15 at 10:34
source share
2 answers

When using Route::controller use this Route::controller('project/dashboard','ProjectController');

And inside your controller, define methods like

 public function getIndex(){ // write your code here } public function postIndex(){ // write your code here } public function getCreate(){ // write your code here } public function postStore(){ // write your code here } 
+1
Nov 30 '15 at 10:47
source share

You are having this problem because this modules directory is not displayed in the Laravel psr module. Based on the laravel version, what you can do is put the modules directory in psr in the composer after "App\\": "app/",

For example: "psr-4": { "App\\": "app/", "Modules\\": "modules/" } in app.php, which is either in app/config/app.php , or config/app.php in laravel 5.

And then run the composer dump-autoload -o . Here you go, now your modules will work as you wish.

If you still have problems, you can try this package, which does the same thing that you are trying to do. https://github.com/yubarajshrestha/laravel-module

0
Dec 16 '16 at 10:47
source share



All Articles