当前位置: 首页>>代码示例>>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;未经允许,请勿转载。