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


PHP Role::whereName方法代码示例

本文整理汇总了PHP中app\models\Role::whereName方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::whereName方法的具体用法?PHP Role::whereName怎么用?PHP Role::whereName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Role的用法示例。


在下文中一共展示了Role::whereName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: destroy

 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function ($query) use($adminName) {
         $query->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->id === auth()->user()->id && count($administrators) === 1) {
         flash()->setTimer(null)->error('Error!', "Unable to remove the administrator role from this user. You're the only administrator.");
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     if ($role->users()->detach($user)) {
         flash()->success('Success!', 'Successfully removed user.');
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     flash()->error('Error!', 'There was an issue removing this user. Please try again.');
     return redirect()->route('admin.roles.show', [$roleId]);
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:35,代码来源:RoleUserController.php

示例2: down

 /**
  * Reverse the migrations.
  *
  * @return void
  */
 public function down()
 {
     Role::whereName('administrator')->delete();
     // Delete Welcome Permission
     Permission::whereName('admin.welcome.index')->delete();
     // Delete User Permissions
     Permission::whereName('admin.users.index')->delete();
     Permission::whereName('admin.users.create')->delete();
     Permission::whereName('admin.users.edit')->delete();
     Permission::whereName('admin.users.show')->delete();
     Permission::whereName('admin.users.destroy')->delete();
     // Delete Role Permissions
     Permission::whereName('admin.roles.index')->delete();
     Permission::whereName('admin.roles.create')->delete();
     Permission::whereName('admin.roles.edit')->delete();
     Permission::whereName('admin.roles.show')->delete();
     Permission::whereName('admin.roles.destroy')->delete();
     // Delete Permission Permissions
     Permission::whereName('admin.permissions.index')->delete();
     Permission::whereName('admin.permissions.create')->delete();
     Permission::whereName('admin.permissions.edit')->delete();
     Permission::whereName('admin.permissions.show')->delete();
     Permission::whereName('admin.permissions.destroy')->delete();
     // Delete User Permission Permissions
     Permission::whereName('admin.users.permissions.store')->delete();
     Permission::whereName('admin.users.permissions.destroy')->delete();
     // Delete Role Permission Permissions
     Permission::whereName('admin.roles.permissions.store')->delete();
     Permission::whereName('admin.roles.permissions.destroy')->delete();
     // Delete Role User Permissions
     Permission::whereName('admin.roles.users.destroy')->delete();
     Permission::whereName('admin.roles.users.destroy')->delete();
 }
开发者ID:stevebauman,项目名称:administration,代码行数:38,代码来源:2014_10_12_300000_seed_roles_and_permissions.php

示例3: handle

 /**
  * Handle an incoming request.
  *
  * @param Request $request
  * @param Closure $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     // Retrieve the administrator role.
     $administrator = $this->role->whereName(Role::getAdministratorName())->first();
     // Retrieve the count of users.
     $users = $this->user->count();
     if ($administrator instanceof Role && !$request->user() && $users === 0) {
         // If the administrator role has been created, no user
         // is logged in, and no users exist,
         // we'll allow the setup request.
         return $next($request);
     }
     // If the administrator role hasn't already been created,
     // we'll throw an Unauthorized Exception.
     throw new HttpException(403, 'Unauthorized.');
 }
开发者ID:stevebauman,项目名称:administration,代码行数:24,代码来源:SetupMiddleware.php

示例4: store

 public function store(LoginAlternativeRequest $request)
 {
     try {
         $credentials['password'] = $request->input('idfacebook');
         $credentials['email'] = $request->input('email');
         $data['tokendevice'] = $request->input('tokendevice');
         $data['typedevice'] = $request->input('typedevice');
         $datauser = User::whereEmail($credentials['email'])->get()->first();
         if (isset($datauser)) {
             if ($datauser->flagactive == User::STATE_USER_INACTIVE) {
                 $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], 'usuario Inactivo');
                 $this->_responseWS->response();
             }
         } else {
             $data = $request->all();
             $data['password'] = Hash::make($data['idfacebook']);
             $obj = User::create($data);
             $datosRol = Role::whereName('user_app')->first();
             $daoUserRol['role_id'] = (int) $datosRol->id;
             $daoUserRol['user_id'] = $obj->id;
             RoleUser::create($daoUserRol);
         }
         $this->login($request->all());
     } catch (\Exception $exc) {
         dd($exc->getMessage());
         $this->_responseWS->setDataResponse(Response::HTTP_INTERNAL_SERVER_ERROR, [], [], '');
     }
     $this->_responseWS->response();
 }
开发者ID:josmel,项目名称:buen,代码行数:29,代码来源:LoginAlternoController.php

示例5: postForm

 public function postForm(FormAdminRequest $request)
 {
     try {
         $dataAdmin = $request->all();
         $password = $request->get('password', null);
         if (isset($dataAdmin['id']) && $dataAdmin['id'] != '') {
             $data = $request->except(array('password'));
             $runtime = User::find($dataAdmin['id']);
             $runtime->fill($data);
             $runtime->password = $runtime->password;
             if (!empty($password)) {
                 $runtime->password = Hash::make($password);
             }
             $runtime->save();
             $msg = 'Usuario Editado!';
         } else {
             $role = Role::whereName(User::ROL_CONTENIDO_ADMIN)->first();
             $dataAdmin['password'] = Hash::make($password);
             $NewUser = User::create($dataAdmin);
             $msg = 'Usuario Guardado!';
             RoleUser::create(['user_id' => $NewUser->id, 'role_id' => $role->id]);
         }
         return redirect(action('Admin\\AdminController@getIndex'))->with('messageSuccess', $msg);
     } catch (Exception $exc) {
         dd($exc->getMessage());
     }
 }
开发者ID:josmel,项目名称:buen,代码行数:27,代码来源:AdminController.php

示例6: revokeRole

 public function revokeRole($role)
 {
     if (is_string($role)) {
         return $this->roles()->detach(Role::whereName($role)->firstOrFail());
     }
     return $this->roles()->detach($role);
 }
开发者ID:phelipperibeiro,项目名称:book_store_laravel,代码行数:7,代码来源:User.php

示例7: store

 /**
  * Store a newly created resource in storage.
  *
  * @param AdduserRequest $request
  * @return \Illuminate\Http\Response
  */
 public function store(AdduserRequest $request)
 {
     //        $input = $request->all();                               // get all data
     //        $input['confirmed'] = 1;                                // set confirmed to 1
     //        $input['password'] = Hash::make($input['password']);    // hash password
     //
     //        $user       =   User::create($input);                   // save above details
     $user = User::create(['first_name' => $request->first_name, 'last_name' => $request->last_name, 'email' => $request->email, 'confirmed' => 1, 'password' => Hash::make($request->password)]);
     //        $profile    =   $user->profile()->save(new Profile);    // also create new profile
     //        $profile->apartment_id  =   Auth::user()->profile->defaultApartment; // get current defaultApartment
     //        $profile->save();                                       // save details on profile
     $profile = Profile::create(['user_id' => $user->id, 'apartment_id' => Auth::user()->profile->defaultApartment]);
     dd(Auth::user()->profile->defaultApartment);
     $role = Role::whereName('user')->first();
     $user->assignRole($role);
     //Assign Role
     $block_no = $request->blockno;
     // get block_no from profileform
     $floor_no = $request->floorno;
     // get floor_no from profileform
     $profile->apartments()->attach($profile->defaultApartment, ['approved' => '1', 'block_no' => $block_no, 'floor_no' => $floor_no]);
     // attach this profile with default apartment, with approved = 1, and block_no, floor_no according to profileform in apartment_profile pivot table.
     Crm_account::create(['account' => $user->first_name . $user->last_name, 'fname' => $user->first_name, 'lname' => $user->last_name, 'company' => 'Company Name', 'email' => $user->email, 'address' => 'Current Address', 'city' => 'Nagpur', 'state' => 'Maharashtra', 'zip' => '440012', 'country' => 'India']);
     return redirect()->back()->withMessage('User has been Added')->withStatus('success');
 }
开发者ID:suchayj,项目名称:easymanage,代码行数:31,代码来源:AdduserController.php

示例8: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = Role::whereName(Role::getAdministratorName())->firstOrFail();
     Permission::all()->map(function ($permission) use($role) {
         $role->grant($permission);
     });
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:12,代码来源:ApplyPermissionsSeeder.php

示例9: run

 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'Admin', 'last_name' => 'Terra', 'email' => 'eduterrajogja@terraversity.com', 'password' => Hash::make('password')));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'John', 'last_name' => 'Doe', 'email' => 'johndoe@terraversity.com', 'password' => Hash::make('password')));
     $user->assignRole($userRole);
 }
开发者ID:teaspoon2504,项目名称:terraversityDev,代码行数:10,代码来源:UserSeeder.php

示例10: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('customer')->first();
     $user = User::create(array('name' => 'hendri', 'email' => 'hendrilara@gmail.com', 'password' => Hash::make('password')));
     $user->assignRole($adminRole);
     $user = User::create(array('name' => 'han', 'email' => 'admin@admin.com', 'password' => Hash::make('admin123')));
     $user->assignRole($userRole);
 }
开发者ID:hendrilara,项目名称:laravel5.1-User-Role,代码行数:15,代码来源:UserTableSeeder.php

示例11: removeRole

 /**
  * @param $role mixed
  * @return $this|Model
  */
 public function removeRole($role)
 {
     if (is_string($role)) {
         return $this->roles()->detach(Role::whereName($role)->firstOrfail());
     }
     if ($role instanceof Role) {
         return $this->roles()->detach($role);
     }
     return $this;
 }
开发者ID:KeepCalmAndPraiseTheSun,项目名称:werashop,代码行数:14,代码来源:HasRoles.php

示例12: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $author = factory(\App\Models\User::class)->create(['name' => 'Author da Silva', 'email' => 'author@admin.com', 'password' => bcrypt(123456)]);
     $author2 = factory(\App\Models\User::class)->create(['name' => 'Author 2 da Silva', 'email' => 'author2@admin.com', 'password' => bcrypt(123456)]);
     factory(\App\Models\Book::class, 2)->create(['user_id' => $author->id]);
     factory(\App\Models\Book::class, 2)->create(['user_id' => $author2->id]);
     $book_manage = factory(\App\Models\Permission::class)->create(['name' => 'book_manage_all', 'description' => 'Can Manage All books']);
     $roleManager = \App\Models\Role::whereName('Manager')->first();
     $roleManager->addPermission($book_manage);
 }
开发者ID:phelipperibeiro,项目名称:book_store_laravel,代码行数:15,代码来源:BookTableSeeder.php

示例13: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('users')->delete();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'Administrator', 'last_name' => 'Account', 'email' => 'admin@email.com', 'password' => Hash::make('123456')));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'Some', 'last_name' => 'User', 'email' => 'some.user@email.com', 'password' => Hash::make('weeeeee')));
     $user->assignRole($userRole);
 }
开发者ID:Timmerdev,项目名称:timmer_app,代码行数:15,代码来源:UserSeeder.php

示例14: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::find(1);
     $user->assignRole($adminRole);
     $user = User::find(2);
     $user->assignRole($userRole);
 }
开发者ID:matthiku,项目名称:cSpot,代码行数:15,代码来源:UserSeeder.php

示例15: run

 public function run()
 {
     DB::statement("SET foreign_key_checks = 0");
     User::truncate();
     $adminRole = Role::whereName('administrator')->first();
     $userRole = Role::whereName('user')->first();
     $user = User::create(array('first_name' => 'Suchay', 'last_name' => 'Janbandhu', 'email' => 'suchayj@easymanage.dev', 'password' => Hash::make('password'), 'confirmed' => 1));
     $user->assignRole($adminRole);
     $user = User::create(array('first_name' => 'Viplove', 'last_name' => 'Wahane', 'email' => 'viplovew@easymanage.dev', 'password' => Hash::make('password'), 'confirmed' => 1));
     $user->assignRole($userRole);
 }
开发者ID:suchayj,项目名称:easymanage,代码行数:11,代码来源:UserSeeder.php


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