update($newDetails); } public function getPermissionListsArrangedByPrefix() { $permissions = self::findAll(); $routeNameArr = []; foreach ($permissions as $permission) { if (!is_null($permission->name)) { $routeName = explode('.', $permission->name); if (is_array($routeName) && !empty($routeName[0])) { $routeNameArr[$routeName[0]][$permission->id] = array_key_exists(1, $routeName) ? $routeName[1] : $routeName[0]; } } } return $routeNameArr; } public static function generatePermissionFromRoutes() { $routes = Route::getRoutes(); foreach ($routes as $route) { $routeName = $route->getName(); $ignoreRoutes = [ 'debugbar', 'login', 'register', 'logout', 'post', 'sanctum', 'ignition', 'welcome', 'home', 'api' ]; $routePrefix = explode('.', $routeName); if (is_array($routePrefix) && !empty($routePrefix[0])) { if (!in_array($routePrefix[0], $ignoreRoutes) && !Permission::where('name', $routeName)->exists()) { Permission::create(['name' => $routeName, 'guard_name' => 'web']); } } } $roles = Role::all(); foreach ($roles as $role) { if ($role->name == 'admin' || $role->name == 'super-admin') { $role->givePermissionTo(Permission::all()); } } } }