本文整理汇总了PHP中Role::whereName方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::whereName方法的具体用法?PHP Role::whereName怎么用?PHP Role::whereName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::whereName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupDatabases
public function setupDatabases()
{
$name = $this->call('migrate', array('--path' => 'app/database/migrations/setup/'));
$name = $this->call('migrate');
// create the roles
$roles = ['Admin', 'Writer', 'Reader'];
foreach ($roles as $r) {
$role = Role::whereName($r)->first();
if ($role == null) {
$role = new Role();
$role->name = $r;
$role->display_name = $r;
$role->save();
$this->info("{$role->id} Creating Role:{$r}");
}
}
foreach (User::all() as $u) {
$this->info("{$u->id} : user: {$u->username}");
}
// add core assets
$m = Asset::findFromTag('missing-user-image');
if ($m == NULL) {
$m = new Asset();
$m->path = "assets/content/uploads";
$m->saveLocalFile(public_path('assets/content/common/missing/profile-default.png'), 'profile-default.png');
$m->tag = 'missing-user-image';
$m->shared = 1;
$m->type = Asset::ASSET_TYPE_IMAGE;
$m->save();
}
$this->comment("****\tAll Databases for Halp have been setup :-) \t****");
return;
}
示例2: run
public function run()
{
DB::table('permission_role')->truncate();
// Assign permissions for Admin role
$admin_role = Role::whereName('admin')->get()->first();
$admin_role->assignPermissions([1, 2, 3, 4, 5, 6, 7]);
// Assign permissions for Member role
$member_role = Role::whereName('member')->get()->first();
$member_role->assignPermissions([2, 3, 4, 5, 6, 7]);
}
示例3: assignRole
/**
* Assign the given role to the user.
*
* @param string $role
* @return mixed
*/
public function assignRole($role)
{
return $this->roles()->save(Role::whereName($role)->firstOrFail());
}
示例4: updateRolePermissions
/**
* Update the specified user in storage.
*
* @param int $id
* @return Response
*/
public function updateRolePermissions()
{
$input = Input::all();
foreach ($input['permissions'] as $role => $permissions) {
Role::whereName($role)->first()->perms()->sync($permissions);
}
return Redirect::route('role.permissions.edit')->with('message', 'Successfully updated role permissions')->with('alert-class', 'success');
}
示例5: getSocialHandle
public function getSocialHandle($provider)
{
$user = Socialite::with($provider)->user();
$socialUser = null;
//Check is this email present
$userCheck = User::where('email', '=', $user->email)->first();
if (!empty($userCheck)) {
$socialUser = $userCheck;
} else {
$sameSocialId = Social::where('social_id', '=', $user->id)->where('provider', '=', $provider)->first();
if (empty($sameSocialId)) {
//There is no combination of this social id and provider, so create new one
$newSocialUser = new User();
$newSocialUser->email = $user->email;
$name = explode(' ', $user->name);
$newSocialUser->first_name = $name[0];
$newSocialUser->last_name = $name[1];
$newSocialUser->save();
$socialData = new Social();
$socialData->social_id = $user->id;
$socialData->provider = $provider;
$newSocialUser->social()->save($socialData);
// Add role
$role = Role::whereName('user')->first();
$newSocialUser->assignRole($role);
$socialUser = $newSocialUser;
} else {
//Load this existing social user
$socialUser = $sameSocialId->user;
}
}
$this->auth->login($socialUser, true);
if ($this->auth->user()->hasRole('user')) {
return redirect()->route('/');
}
if ($this->auth->user()->hasRole('administrator')) {
return redirect()->route('/backoffice');
}
return \App::abort(500);
}
示例6: storeMiniAdmin
public function storeMiniAdmin()
{
$user = $this->user;
$data = Input::only('email', 'password');
if (!$user->is_valid($data)) {
return Redirect::back()->withInput()->withErrors(User::$errors);
}
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
$role = Role::whereName('miniadmin')->first();
$user->roles()->attach($role->id);
return Redirect::to('/admin/miniadmin');
}
示例7: editUserRoles
public function editUserRoles($id)
{
$user = User::findOrFail($id);
if ($user) {
$current_roles = $user->roles;
$spotter_role = Role::whereName('Writer')->first();
$has_spotter_role = false;
$rolesToAttach = [];
foreach (Input::get('roles') as $key => $value) {
$role = Role::where('id', '=', $key)->first();
if ($key == $spotter_role->id) {
$has_spotter_role = true;
}
if ($role) {
array_push($rolesToAttach, $key);
}
}
if (count($rolesToAttach) > 0) {
$user->roles()->sync($rolesToAttach);
}
$had_spotter_role_already = false;
foreach ($current_roles as $role) {
if ($role->id == $spotter_role->id) {
$had_spotter_role_already = true;
}
}
if ($has_spotter_role && $had_spotter_role_already == false) {
// Activity::createActivityAndFire([
// 'name'=>Activity::ACTIVITY_USER_SPOTTER,
// 'timestamp'=>Carbon\Carbon::now(),
// 'parent'=>$user,
// 'user_id'=>$user->id
// ]);
}
return Redirect::back()->with('notice', 'User updated');
}
return Redirect::back()->with('error', 'Could not find user');
}
示例8: saveUser
private function saveUser()
{
$user = new User();
$role = Input::get('role') ? Role::whereName(strtolower(Input::get('role')))->first() : Role::whereName('member')->first();
$user->name = Input::get('name');
$user->username = Input::get('username');
$user->password = Hash::make(Input::get('password'));
$user->email = Input::get('email');
$user->address = Input::get('address');
$user->telephone = Input::get('telephone');
$user->city = Input::get('city');
$user->role_id = $role->id;
$user->active = Input::get('active') ?: 1;
$user->save();
}