1212use Jaspaul \LaravelRollout \Console \CreateCommand ;
1313use Jaspaul \LaravelRollout \Console \DeleteCommand ;
1414use Jaspaul \LaravelRollout \Console \AddUserCommand ;
15+ use Jaspaul \LaravelRollout \Console \AddGroupCommand ;
1516use Jaspaul \LaravelRollout \Console \EveryoneCommand ;
1617use Illuminate \Contracts \Config \Repository as Config ;
1718use Jaspaul \LaravelRollout \Console \DeactivateCommand ;
1819use Jaspaul \LaravelRollout \Console \PercentageCommand ;
1920use Jaspaul \LaravelRollout \Console \RemoveUserCommand ;
21+ use Jaspaul \LaravelRollout \Console \RemoveGroupCommand ;
2022use Illuminate \Support \ServiceProvider as IlluminateServiceProvider ;
2123
2224class ServiceProvider extends IlluminateServiceProvider
@@ -44,17 +46,21 @@ public function boot()
4446 $ driver = new Cache ($ app ->make ('cache.store ' ));
4547 }
4648
47- return new Rollout ($ driver );
49+ $ this ->loadGroups ($ rollout = new Rollout ($ driver ), $ config ->get ('laravel-rollout.groups ' ));
50+
51+ return $ rollout ;
4852 });
4953
5054 $ this ->commands ([
55+ AddGroupCommand::class,
5156 AddUserCommand::class,
5257 CreateCommand::class,
5358 DeactivateCommand::class,
5459 DeleteCommand::class,
5560 EveryoneCommand::class,
5661 ListCommand::class,
5762 PercentageCommand::class,
63+ RemoveGroupCommand::class,
5864 RemoveUserCommand::class
5965 ]);
6066 }
@@ -67,7 +73,8 @@ public function boot()
6773 public function register ()
6874 {
6975 $ this ->mergeConfigFrom (
70- __DIR__ .'/../resources/config/laravel-rollout.php ' , 'laravel-rollout '
76+ __DIR__ .'/../resources/config/laravel-rollout.php ' ,
77+ 'laravel-rollout '
7178 );
7279 }
7380
@@ -92,4 +99,19 @@ protected function loadMigrations()
9299 {
93100 $ this ->loadMigrationsFrom (__DIR__ .'/../resources/migrations ' );
94101 }
102+
103+ /**
104+ * Loads our groups
105+ *
106+ * @return void
107+ */
108+ protected function loadGroups (Rollout $ rollout , array $ groups )
109+ {
110+ foreach ($ groups as $ group ) {
111+ $ instance = resolve ($ group );
112+ $ rollout ->defineGroup ($ instance ->getName (), function ($ user = null ) use ($ instance ) {
113+ return $ instance ->hasMember ($ user );
114+ });
115+ }
116+ }
95117}
0 commit comments