/** * Execute the console command. * * @return mixed */ public function handle() { $permissions = $this->getAllActions(); $actions = $this->getRouteData(); $roles = Role::all(); // Add new actions foreach ($actions as $action => $uri) { if (!array_key_exists($action, $permissions)) { $newAction = new Action(['action' => $action, 'uri' => $uri]); $newAction->save(); $this->savePermissions($roles, $newAction); $this->info("Added " . $action . "\n"); } else { unset($permissions[$action]); } } // Remove non existing actions foreach ($permissions as $action => $uri) { Action::where(['action' => $action, 'uri' => $uri])->first()->destroy(); $this->comment("Removed " . $action . "\n"); } $cache = $this->getCacheInstance(['permissions']); $cache->flush(); $this->info("Done. \n"); }