當前位置: 首頁>>代碼示例>>PHP>>正文


PHP User::roles方法代碼示例

本文整理匯總了PHP中app\User::roles方法的典型用法代碼示例。如果您正苦於以下問題:PHP User::roles方法的具體用法?PHP User::roles怎麽用?PHP User::roles使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\User的用法示例。


在下文中一共展示了User::roles方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: updateRoles

 /**
  * Assign permissions to user
  */
 public function updateRoles(Request $request, User $user)
 {
     $roles = $request->checkedRoles ?: [];
     // $roles = array of submitted roles OR if all checkboxes were unchecked, make it an empty array
     $user->roles()->sync($roles);
     logThis('Roles for ' . $user->name . ' changed to ' . $user->roles()->lists('label'));
     return $user->load('roles');
 }
開發者ID:goatatwork,項目名稱:access2,代碼行數:11,代碼來源:UsersApiController.php

示例2: save

 public function save(Request $request)
 {
     $input = $request->all();
     // $field_name = implode('|',$input['website']['locales']);
     $company = new Company();
     $company->name = $input['client']['company_name'];
     $company->alias = $input['website']['sub_name'];
     $company->save();
     $user = new User();
     $user->name = $input['client']['name'];
     $user->email = $input['client']['email'];
     $user->password = $input['client']['password'];
     $user->ip = '*';
     $user->branch_id = 1;
     $user->company_id = $company->id;
     $user->active = 1;
     $user->save();
     $user->roles()->attach(Role::find(1)->id);
     // $gr_fields = new GrFields;
     // $gr_fields->field_name = $field_name;
     // $gr_fields->company_id = $company->id;
     // $gr_fields->save();
     session(['input' => $input]);
     return redirect('thanks');
 }
開發者ID:sahilbhatt92,項目名稱:transpt,代碼行數:25,代碼來源:CompanyController.php

示例3: store

 public function store(Request $request)
 {
     $club = Club::where('_id', $request->get('club_id'))->first();
     $team = $club->teams()->where('_id', $request->get('team_id'))->first();
     $user = User::where('email', $request->get('email'))->first();
     if (empty($user)) {
         $user = new User();
         $user->first_name = $request->get('first_name');
         $user->last_name = $request->get('last_name');
         $user->email = $request->get('email');
         $user->position = $request->get('position');
         $user->active = false;
         $user->save();
         //team
         $role = new Role();
         $role->club_id = $club->_id;
         $role->club_name = $club->name;
         $role->team_id = $team->_id;
         $role->team_name = $team->name;
         $role->role = 'player';
         $user->roles()->save($role);
         return response()->json($user, 200);
     } else {
         return response()->json(array('message' => 'user registered'), 200);
     }
 }
開發者ID:lookstechnical,項目名稱:handbook-api,代碼行數:26,代碼來源:PlayersContoller.php

示例4: update

 /**
  * Update user
  *
  * @param UserUpdateRequest $request
  * @param $user
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update(UserUpdateRequest $request, User $user)
 {
     $user->update($request->only('email', 'password') + ['name' => $request->get('username'), 'email' => $request->get('email')]);
     if ($request->has('password')) {
         $user->update($request->only('email', 'password') + ['password' => Hash::make($request->get('password'))]);
     }
     $user->roles()->sync($request->get('roles'));
     return redirect()->route('manager.user.index')->with(['message' => 'Сохранен']);
 }
開發者ID:devillom,項目名稱:simpleshop,代碼行數:16,代碼來源:UserController.php

示例5: postCreateUser

 public function postCreateUser(Request $request)
 {
     $user = new User();
     $user->login = $request->get("login");
     $user->name = $request->get("name");
     $user->email = $request->get("email");
     $user->password = Hash::make($request->get("password"));
     $user->save();
     $user->roles()->attach($request->get("role_select"));
     return redirect('/personal/user/list');
 }
開發者ID:neolinks,項目名稱:cabinet,代碼行數:11,代碼來源:UsersController.php

示例6: register

 public function register()
 {
     $user = new User();
     $request = Request::all();
     $user->name = $request['name'];
     $user->email = $request['email'];
     $user->password = bcrypt($request['password']);
     $user->save();
     $user->roles()->attach($request['role_id']);
     return redirect('/auth/login');
 }
開發者ID:cihannalp,項目名稱:Laravel-Blog,代碼行數:11,代碼來源:AuthController.php

示例7: viewWeeklyReport

 public function viewWeeklyReport()
 {
     $allowed = ['Admin', 'Project Manager'];
     $userRoles = User::roles();
     foreach ($userRoles as $role) {
         if (in_array($role->role, $allowed)) {
             return true;
         }
     }
     return false;
 }
開發者ID:snehachavan21,項目名稱:timesheet,代碼行數:11,代碼來源:TrackerPolicy.php

示例8: delete

 public function delete()
 {
     $allowed = ['Admin'];
     $userRoles = User::roles();
     foreach ($userRoles as $role) {
         if (in_array($role->role, $allowed)) {
             return true;
         }
     }
     return false;
 }
開發者ID:komalsavla10,項目名稱:timesheet,代碼行數:11,代碼來源:TagPolicy.php

示例9: store

 public function store(Request $request)
 {
     $user = new User();
     $rules = ['name' => 'required', 'email' => 'required|email|unique:users', 'roles_id' => 'array', 'password' => 'required|min:6|confirmed'];
     $this->validate($request, $rules);
     $user->name = $request->input('name');
     $user->email = $request->input('email');
     $user->password = bcrypt($request->input('password'));
     $user->save();
     $user->roles()->sync($request->input('roles_id', []));
     return redirect()->route('dashboard.user.index')->with('infos', new MessageBag(["新增用戶" . $user['name']]));
 }
開發者ID:sixbyter,項目名稱:laradmin,代碼行數:12,代碼來源:UserController.php

示例10: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $user = new User();
     $request = Request::all();
     $role = Role::find($request['user']);
     $user->name = $request['name'];
     $user->email = $request['email'];
     $user->password = bcrypt($request['password']);
     $user->save();
     $user->roles()->attach($role->id);
     return redirect('/admin/users');
 }
開發者ID:cihannalp,項目名稱:Laravel-Blog,代碼行數:18,代碼來源:UsersController.php

示例11: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // TODO: add check if current user is admin before he can add another admin
     $a = new User();
     if (!$a->validate(Input::all())) {
         return redirect('user/create')->withErrors($a->errors())->withInput();
     }
     $a->fill(Input::all());
     $a->save();
     $a->roles()->attach(Input::get('role'));
     Flash::success('New user is created');
     return Redirect::to('user');
 }
開發者ID:e11en,項目名稱:laravel_basic,代碼行數:19,代碼來源:UserController.php

示例12: store

 /**
  * Store a newly created user in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $users = User::all();
     $this->validate($request, ['name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6|confirmed']);
     $user = new User();
     $user->name = Input::get('name');
     $user->email = Input::get('email');
     $user->password = bcrypt(Input::get('password'));
     $user->save();
     $role = Input::get('roles');
     $user->roles()->attach($role);
     Session::flash('success', 'User was successful added!');
     return redirect('admin/users');
 }
開發者ID:waeltech,項目名稱:lara,代碼行數:19,代碼來源:UserController.php

示例13: __construct

 public function __construct()
 {
     $allowed = ['Admin', 'Project Manager'];
     $userRoles = User::roles();
     $flag = false;
     foreach ($userRoles as $role) {
         if (in_array($role->role, $allowed)) {
             $flag = true;
         }
     }
     if (true != $flag) {
         abort(403, 'Now allowed');
     }
 }
開發者ID:komalsavla10,項目名稱:timesheet,代碼行數:14,代碼來源:ManagerController.php

示例14: store

 public function store(Request $request, $id = null)
 {
     if (isset($id)) {
         if ($request->input('password')) {
             $validator = Validator::make($request->only('username', 'email', 'password', 'password_confirmation'), $this->user->update_rules_with_password);
         } else {
             $validator = Validator::make($request->only('username', 'email', 'password', 'password_confirmation'), $this->user->update_rules);
         }
     } else {
         $validator = Validator::make($request->only('username', 'email', 'password', 'password_confirmation'), $this->user->create_rules);
     }
     if ($validator->passes()) {
         if (isset($id)) {
             $user = $this->user->find($id);
         } else {
             $user = new User();
         }
         $user->username = $request->input('username');
         $user->email = $request->input('email');
         if ($request->input('password')) {
             $user->password = Hash::make($request->input('password'));
         }
         $user->save();
         $role = Role::where('role_name', 'admin')->first();
         if ($request->input('admin')) {
             $user->roles()->attach($role);
         } else {
             if ($user->hasRole('admin')) {
                 $user->roles()->detach($role);
             }
         }
         return redirect()->to('users')->with(['success' => 'Saved ' . $user->username]);
     } else {
         return redirect()->back()->withInput()->withErrors($validator->messages());
     }
 }
開發者ID:mikeminckler,項目名稱:unilog,代碼行數:36,代碼來源:UsersController.php

示例15: update

 public function update(Request $request, User $user)
 {
     $user->name = $request->name;
     $user->email = $request->email;
     $user->password = bcrypt(checkPassword($user->password, $request->password));
     $user->save();
     if (!$request->input('role_list')) {
         $roleList = [];
     } else {
         $roleList = $request->input('role_list');
     }
     $user->roles()->sync($roleList);
     Flash::success('User Updated!');
     return redirect()->action('UserController@index');
 }
開發者ID:tindase,項目名稱:uc-insight,代碼行數:15,代碼來源:UserController.php


注:本文中的app\User::roles方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。