当前位置: 首页>>代码示例>>PHP>>正文


PHP Role::whereName方法代码示例

本文整理汇总了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;
 }
开发者ID:vanderlin,项目名称:halp,代码行数:33,代码来源:CreateDatabases.php

示例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]);
 }
开发者ID:pogliozzy,项目名称:larabase,代码行数:10,代码来源:PermissionRoleTableSeeder.php

示例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());
 }
开发者ID:sportyboty,项目名称:laravel-5-roles-and-permissions-demo,代码行数:10,代码来源:HasRoles.php

示例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');
 }
开发者ID:razerbite,项目名称:frisco_foundry,代码行数:14,代码来源:UsersController.php

示例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);
 }
开发者ID:zekaroz,项目名称:Opel,代码行数:40,代码来源:AuthController.php

示例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');
 }
开发者ID:imsgithub,项目名称:hotlot.com,代码行数:14,代码来源:UsersController.php

示例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');
 }
开发者ID:vanderlin,项目名称:halp,代码行数:38,代码来源:UsersController.php

示例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();
 }
开发者ID:udayrockstar,项目名称:RestaurantManager,代码行数:15,代码来源:UsersController.php


注:本文中的Role::whereName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。