I’m back!

The last post was almost a year ago, I haven’t had time to post but starting today I will post as often as possible (version 4 of course)


How to organize base controllers

Situation: we have an application with multiple modules, each one needs a base controller that will handle common stuff for them, I prefer having a folder called “base_controllers” in application folder to keep it organized.

By default, Laravel’s base controller is in controllers folder(base.php) and it’s mapped in start.php with Autoloader::map().

To implement my way follow these 3 simple steps:

1. Delete base.php from controllers(if you don’t need it anymore)

2. Create base_controllers folder in /application/base_controllers and create the base controllers you need e.g. Base1.php and Base2.php:

Base1_Controller extends Controller {}
Base2_Controller extends Controller {}

3. To make it work(controllers to extend them) we have to ways:

3.1 In start.php with Autoloader::map() each one individually:

     'Base1_Controller' => path('app').'base_controllers/Base1.php',
     'Base2_Controller' => path('app').'base_controllers/Base2.php',

3.2 In start.php with Autoloader::directories():


Note: Laravel’s autoloader will search the directories using the PSR-0 naming convention.