public function run() { Model::unguard(); // Create no permissions role Role::create(['role_title' => 'No Permissions', 'role_description' => 'No Permissions']); // Create all permissions role $admin = Role::create(['role_title' => 'Admin', 'role_description' => 'All Permissions']); // Assign all permission to the admin $this->dispatch(new SetPermissions([$admin->id])); }
/** * Assign permissions to roles * * @param Collection $permissions */ private function assignPermissions(Collection $permissions) { $roles = Role::whereIn('id', $this->role_ids)->get(); if ($roles && $permissions) { $permission_ids = $permissions->lists('id')->all(); foreach ($roles as $role) { $role->permissions()->attach($permission_ids); } } }
/** * Remove the specified resource from storage. * * @param int $id * * @return Response */ public function destroy($id) { // Get the first permission that is not this one that we are trying to delete $default_permission = Role::findOrFail(1); // Build users model based on Auth config model $user_model = config('auth.model'); // Update all the users that have this role. Assign them the default role. $user_model::where('role_id', '=', $id)->update(['role_id' => $default_permission->id]); // Delete the requested role. $role = Role::findOrFail($id); $role->delete(); return redirect()->action('\\Aginev\\Acl\\Http\\Controllers\\RoleController@index')->with('success', trans('acl::role.destroy.deleted')); }