Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hungneox/58745468e448d0cc41f8da8dbcfc7dfb to your computer and use it in GitHub Desktop.
Save hungneox/58745468e448d0cc41f8da8dbcfc7dfb to your computer and use it in GitHub Desktop.
Simple Module Concept for Laravel 5
<?php
namespace App\Providers;
use Illuminate\Support\ModuleServiceProvider;
class FooModuleServiceProvider extends ModuleServiceProvider
{
protected $moduleName = 'Foo Module';
protected $moduleNamespaces = ['App\FooModule'];
protected $controllerNamespace = ['App\FooModule\Http\Controllers'];
public function register() { }
public function boot()
{
//bindings registered here will only be applied to classes with a namespace matching $moduleNamespaces
//if no binding is found, falls through to the primary IoC container
$this->app->bind(SomeRepository::class, function($app)
{
$repository = $app->make(SomeRepository::class);
return new SomeRepositoryAccessControlDecorator($repository);
}, $this->moduleNamespaces)
}
}
<?php
Route::group(['module' => 'Foo Module'], function(){
/* etc... */
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment