@@ -41,26 +41,38 @@ public function __construct()
4141 public function handle ()
4242 {
4343 $ options = $ this ->options ();
44- if ($ options ['fresh ' ]){
44+
45+ if ($ options ['fresh ' ]) {
4546 Permission::query ()->delete ();
4647 Role::query ()->delete ();
4748 }
49+
4850 $ routes = Route::getRoutes ()->getRoutes ();
4951
5052 foreach ($ routes as $ route ){
5153 $ action = $ route ->getActionname ();
52- if ($ action == "Closure " ){
54+
55+ if ($ action == "Closure " ) {
5356 continue ;
5457 }
55- $ name = $ route ->getName ();
5658
59+ $ name = $ route ->getName ();
5760 $ permission = Permission::firstOrCreate (['action ' =>$ action , 'name ' =>$ name ]);
5861
59- if (key_exists ('role ' , $ route ->action )){
60- $ role = $ route ->action ['role ' ];
61- $ role = Role::firstOrCreate (['name ' => $ role ]);
62+ if (key_exists ('role ' , $ route ->action )) {
63+ $ roles = $ route ->action ['role ' ];
64+
65+ if (is_array ($ roles )) {
66+ foreach ($ roles as $ role ) {
67+ $ role = Role::firstOrCreate (['name ' => $ role ]);
68+
69+ $ role ->permissions ()->syncWithoutDetaching ($ permission ->id );
70+ }
71+ } else {
72+ $ role = Role::firstOrCreate (['name ' => $ roles ]);
6273
63- $ role ->permissions ()->syncWithoutDetaching ($ permission ->id );
74+ $ role ->permissions ()->syncWithoutDetaching ($ permission ->id );
75+ }
6476 }
6577 }
6678 }
0 commit comments