本文整理汇总了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');
}
示例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');
}
示例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);
}
}
示例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' => 'Сохранен']);
}
示例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');
}
示例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');
}
示例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;
}
示例8: delete
public function delete()
{
$allowed = ['Admin'];
$userRoles = User::roles();
foreach ($userRoles as $role) {
if (in_array($role->role, $allowed)) {
return true;
}
}
return false;
}
示例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']]));
}
示例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');
}
示例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');
}
示例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');
}
示例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');
}
}
示例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());
}
}
示例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');
}