Last active
July 18, 2018 11:40
-
-
Save thepsion5/8cac4ab06a00d38770f7 to your computer and use it in GitHub Desktop.
Simple Module Concept for Laravel 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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