Share on Facebook0Tweet about this on Twitter0Share on Google+0Share on TumblrEmail this to someone

If you like to put your controllers, models and views folders within one folder in Laravel 4.2. Here is the simplest way :

First Create folder “modules” (your desire¬†directory name) in root directory and Create directories and files under modules. Your directory structure should like this:

|-app
|-modules
 |-controllers
   |-admin
     |-AdminController.php
   |-frontend
     |-PageController.php
 |-models
   |-admin
     |-user.php
   |-frontend
     |-page.php
|-views
   |-admin
     |-login.php
   |-frontend
     |-home.php

Update path of controllers and models in composer.json

"autoload": {
 "classmap": [
 "modules/commands",
 "modules/controllers",
 "modules/models",
 "app/database/migrations",
 "app/database/seeds",
 "app/tests/TestCase.php"
 ]
 },

Put the following code in app/start/global.php

View::addLocation(app('path').'/../modules/views/');
View::addNamespace('admin', app('path').'/../modules/views/admin/');
View::addNamespace('frontend', app('path').'/../modules/views/frontend/');

then run

'php artisan dump-autoload' or 'composer dump-autoload' 

Remember whenever you create new file in modules you need to run above command.