Skip to content

Instantly share code, notes, and snippets.

@thepsion5
Last active July 18, 2018 11:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thepsion5/8cac4ab06a00d38770f7 to your computer and use it in GitHub Desktop.
Save thepsion5/8cac4ab06a00d38770f7 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