本文整理汇总了PHP中app\Role::whereName方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::whereName方法的具体用法?PHP Role::whereName怎么用?PHP Role::whereName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Role
的用法示例。
在下文中一共展示了Role::whereName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addRole
/**
* Add a Role to a User
*
* @param multiple $role Role to add, might by instance of Role or name of role as string
*/
public function addRole($role)
{
if (is_string($role)) {
$role = Role::whereName($role)->firstOrFail();
}
return $this->roles()->save($role);
}
示例2: assign
/**
* Assign role(s) to a user.
*
* @param string|object $role
* @return boolean
*/
public function assign($role)
{
if (is_string($role)) {
return $this->roles()->save(Role::whereName($role)->firstOrFail());
}
return $this->roles()->save($role);
}
示例3: create
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
$user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
$organisation = Organisation::create(['name' => $data['organisationName']]);
$role = Role::whereName('owner')->first();
$userOrganisationRole = new UserOrganisationRole(['user_id' => $user->id, 'organisation_id' => $organisation->id, 'role_id' => $role->id]);
$user->organisationRoles()->save($userOrganisationRole);
return $user;
}
示例4: store
/**
* save a user
* @param $data
*/
public function store($data)
{
$data = $this->prepareData($data);
$user = $this->model->create($data);
$role = isset($data['role']) ? $data['role'] : Role::whereName('member')->first();
$user->createProfile();
$user->assignRole($role);
return $user;
}
示例5: assignRole
public function assignRole($role)
{
// if given is string
if (is_string($role)) {
return $this->roles()->save(Role::whereName($role)->firstOrfail());
}
// given is collection
return $this->roles()->save($role);
}
示例6: run
public function run()
{
DB::table('role_user')->delete();
$user = User::whereName('corean')->FirstOrFail();
$role_id = Role::whereName('manager')->pluck('id');
$user->saveRoles([$role_id[0]]);
$user = User::whereName('test')->FirstOrFail();
$role_id = Role::whereName('member')->pluck('id');
$user->saveRoles([$role_id[0]]);
}
示例7: ownAdminRole
/**
* An admin can not remove its own admin privileges
*
* @return bool
*/
public function ownAdminRole($attribute, $value, $parameters, $validator)
{
$userId = $parameters[0];
$ownId = $parameters[1];
$adminRoleId = Role::whereName('admin')->pluck('id')->first();
if (in_array($adminRoleId, $value)) {
return true;
}
return $userId != $ownId;
}
示例8: run
public function run()
{
DB::table('users')->delete();
$adminRole = Role::whereName('administrator')->first();
$userRole = Role::whereName('user')->first();
$user = User::create(array('first_name' => 'John', 'last_name' => 'Doe', 'email' => 'j.doe@codingo.me', 'password' => Hash::make('password')));
$user->assignRole($adminRole);
$user = User::create(array('first_name' => 'Jane', 'last_name' => 'Doe', 'email' => 'jane.doe@codingo.me', 'password' => Hash::make('janesPassword')));
$user->assignRole($userRole);
}
示例9: register
public function register($data)
{
$user = new User();
$user->email = $data['email'];
$user->first_name = ucfirst($data['first_name']);
$user->last_name = ucfirst($data['last_name']);
$user->password = Hash::make($data['password']);
$user->save();
//Assign Role
$role = Role::whereName('user')->first();
$user->assignRole($role);
}
示例10: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$user = Auth::user();
//dd($user->email);
if ($user) {
$role = Role::whereName('guest')->first();
if ($user->hasRole($role)) {
return $next($request);
}
}
return redirect('/');
}
示例11: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$role = Role::whereName('admin')->firstOrFail();
$role->addPermission('permissions-index');
$role->addPermission('permissions-create');
$role->addPermission('permissions-edit');
$role->addPermission('roles-index');
$role->addPermission('roles-create');
$role->addPermission('roles-edit');
$role->addPermission('users-index');
$role->addPermission('users-create');
$role->addPermission('users-edit');
}
示例12: store
public function store($data)
{
$data = $this->prepareData($data);
$data['image'] = isset($data['image']) ? $this->storeImage($data['image'], $data['name'] . '-' . getUniqueNumber(), 'sellers', null, null, 640, null, false) : '';
$seller = $this->model->create($data);
$profile = new Profile($data);
$seller->createProfile($profile);
$role = isset($data['role']) ? $data['role'] : Role::whereName('seller')->firstOrFail();
$seller->assignRole($role);
if (isset($data['clients'])) {
$seller->assignClient($data['clients']);
}
return $seller;
}
示例13: create_user
/**
* Function create user
* @author Tran Van Moi <[moitran92@gmail.com]>
* @since 2015/05/13
* @param array $user_info
* @param string $role_name
* @return object
*/
public static function create_user($user_info, $role_name)
{
$user = new User();
$user->name = $user_info['name'];
$user->uid = empty($user_info['id']) ? 'res_local' : $user_info['id'];
$user->email = $user_info['email'];
$user->image = $user_info['image'];
$user->password = Hash::make($user_info['password']);
if (isset($user_info['birthday'])) {
$user->birthday = $user_info['birthday'];
}
if (isset($user_info['address'])) {
$user->address = $user_info['address'];
}
$user->save();
// attack role to user
$role = Role::whereName($role_name)->first();
$user->attachRole($role);
return $user;
}
示例14: updateRoles
public function updateRoles(User $user, Request $request, $user_id)
{
$userModel = User::find($user_id);
$userModel->name = $request->get('name');
$userModel->email = $request->get('email');
$userModel->save();
// detach role from user
$userModel->detachRoles(Role::all());
//insert new roles
foreach ($request->get('role') as $role_request) {
$userModel->attachRole(Role::whereName($role_request)->first());
}
return Redirect::back()->with('msg', ' was successfully updated.');
}
示例15: apiRoleDetails
/**
* API for retrieving details of a single role
*/
public function apiRoleDetails(Role $role)
{
return $roleWithPermissions = Role::whereName($role->name)->with('permissions')->first();
}