/** * Save data. * * @param Request $request Request * @param ID $role_id ID * * @return int */ public function saveData($request, $role_id) { $roles = new Role(); $role = $roles->find($role_id); $array_permission = $request->input('permission'); foreach ($array_permission as $value) { $permission = new self(); $permission->permission_title = $value; $permission->permission_slug = $value; $results = $permission->save(); if (!$results) { return $results; } else { $role->permissions()->attach($permission->id); } } return $results; }
/** * Run the database seeds. * * @return void */ public function run() { if (App::environment() === 'production') { exit('I just stopped you getting fired. Love, Amo.'); } DB::table('roles')->truncate(); Role::create(['id' => 1, 'role_title' => 'Root', 'role_slug' => 'Root', 'description' => 'Use this account with extreme caution. When using this account it is possible to cause irreversible damage to the system.']); Role::create(['id' => 2, 'role_title' => 'Administrator', 'role_slug' => 'Administrator', 'description' => 'Full access to create, edit, and update companies, and orders.']); Role::create(['id' => 3, 'role_title' => 'Manager', 'role_slug' => 'Manager', 'description' => 'Ability to create new companies and orders, or edit and update any existing ones.']); Role::create(['id' => 4, 'role_title' => 'User', 'role_slug' => 'User', 'description' => 'A standard user that can have a licence assigned to them. No administrative features.']); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * * @return \Illuminate\Http\Response */ public function update(Request $request) { $role = new Role(); $user = new User(); $user_id = $request->route('user'); $info_user = $user->find($user_id); // $info = $info_user->roles()->get(); if ($info_user) { $array_role = array(); foreach ($info_user->roles as $role) { $array_role[] = $role->pivot->role_id; } $list_role = $role->selectBoxRole($array_role); return view('admin.user.updateuser', compact('list_role', 'info_user')); } else { return redirect()->route('cpanel.user.index')->with('status', 'fail')->with('msg', 'User not available.'); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request Request * * @return \Illuminate\Http\Response */ public function update(Request $request) { $modules = Module::with('actions')->get(); $role_id = $request->route('groupuser'); $roles = new Role(); $role = $roles->find($role_id); $permission = $role->permissions()->get(); $array_permission = array(); foreach ($permission as $value) { $array_permission[] = $value->permission_slug; } $action_configs = \Config::get('action'); return view('admin.user.updategroup', compact('modules', 'role', 'array_permission', 'action_configs')); }