Modules in Laravel 4

Published on Oct 8, 2013

I previously published a simple tutorial post on taking the modular approach to building your applications in Laravel 4, but since then I needed a solution that I could use easily on different projects, so this was a no brainer, and I built a composer package for this purpose.

It's located at: https://github.com/creolab/laravel-modules

You can install it by adding a new dependency to your composer.json file:

"creolab/laravel-modules": "dev-master"

Then running "composer dump", and after that adding a new service provider to "app/config/app.php":

'Creolab\LaravelModules\ServiceProvider'

Now you can create your modules directory under "app/modules", but you also need to enable autoloading for this directory by placing it in your autoload class inside "composer.json":

"autoload": {
	"classmap": [
    	"app/modules"
	]
}

Keep in mind that every time you create a new class in your module, you need to run "composer dump" if you set it up as above.

You could also set it up to autoload as PSR-0, but that would require a different directory structure, which I don't like for this :)

Example

Anyway, you can see an example implementation here: https://github.com/bstrahija/laravel-modules-example

The package is fairly fresh so any feedback is appreciated.

New Vendor Name

As you might see I published the package on Github and Packagist under a new vendor name, so in the future I'm going to release most of my packages under this vendor name:

https://github.com/creolab
https://packagist.org/packages/creolab/