/** * Execute the console command. * * @return mixed */ public function handle() { $this->info("Clearing permissions... \n"); // Delete old data $response = Action::deleteAllData(); null !== $response ? $this->error("\n" . $response . "\n") : null; $this->info("Permissions cleared... \n"); try { $routeData = $this->getRouteData(); $roles = Role::all(); DB::beginTransaction(); foreach ($routeData as $action => $uri) { $action = new Action(['uri' => $uri, 'action' => $action]); $action->save(); $this->savePermissions($roles, $action); $this->comment("Added action " . $action->action . "\n"); } $cache = $this->getCacheInstance(['permissions']); $cache->flush(); DB::commit(); } catch (\Exception $e) { DB::rollBack(); $this->error("\n" . $e->getMessage() . "\n"); } }