コード例 #1
0
 /**
  * Add a new role.
  *
  * @param  \App\Board  $board
  * @return Response
  */
 public function putAdd(Board $board)
 {
     if (!$this->user->canEditConfig($board)) {
         return abort(403);
     }
     $roles = Role::whereCanParentForBoard($board, $this->user)->get();
     $castes = $board->getRoleCastes(Input::get('roleType'))->get()->pluck('caste');
     $rules = ['roleType' => ["required", "string", "in:" . $roles->lists('role')->implode(",")], 'roleCaste' => ["string", "alpha_num", "unique:roles,role,{$board->board_uri},board_uri"], 'roleName' => ["string"], 'roleCapcode' => ["string"]];
     $validator = Validator::make(Input::all(), $rules);
     $validator->sometimes('roleCaste', "not_in:" . $castes->implode(","), function ($input) use($castes) {
         return $castes->count();
     });
     if ($validator->fails()) {
         return redirect()->back()->withInput()->withErrors($validator->errors());
     }
     $role = new Role();
     $role->board_uri = $board->board_uri;
     $role->inherit_id = $roles->where('role', strtolower(Input::get('roleType')))->pluck('role_id')[0];
     $role->role = strtolower(Input::get('roleType'));
     $role->caste = strtolower(Input::get('roleCaste'));
     $role->name = Input::get('roleName') ?: "user.role.{$role->role}";
     $role->capcode = Input::get('roleCapcode');
     $role->weight = 5 + constant(Role::class . "::WEIGHT_" . strtoupper(Input::get('roleType')));
     $role->save();
     return redirect($role->getPermissionsURLForBoard());
 }