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


PHP Role::where方法代码示例

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


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

示例1: update

 /**
  * Update roles.
  *
  * @param  array  $inputs
  * @return void
  */
 public function update($inputs)
 {
     foreach ($inputs as $key => $value) {
         $role = $this->role->where('slug', $key)->firstOrFail();
         $role->title = $value;
         $role->save();
     }
 }
开发者ID:arissetyawan,项目名称:laravel5-example,代码行数:14,代码来源:RoleRepository.php

示例2: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = Role::where('name', 'admin')->first();
     $customer = Customer::create(['name' => 'test']);
     $customer->user()->save(new User(['email' => 't@t.test', 'password' => bcrypt('testing')]));
     $customer->user->assignRole($role);
 }
开发者ID:RichardMarbach,项目名称:mkdir,代码行数:12,代码来源:UserTableSeeder.php

示例3: create

 /**
  * @param  $input
  * @throws GeneralException
  * @return bool
  */
 public function create(array $input)
 {
     if (Role::where('name', '=', $input['name'])->first()) {
         throw new GeneralException('That role already exists. Please choose a different name.');
     }
     if (isset($input['assignees_permissions']) && count($input['assignees_permissions']) == 0) {
         throw new GeneralException('You must select at least one permission for this role.');
     }
     $role = new Role();
     $role->name = $input['name'];
     $role->display_name = $input['display_name'];
     $role->description = $input['description'];
     if ($role->save()) {
         $current = $input['assignees_permissions'];
         $permissions = [];
         if (count($current)) {
             foreach ($current as $perm) {
                 if (is_numeric($perm)) {
                     array_push($permissions, $perm);
                 }
             }
         }
         $role->attachPermissions($permissions);
         return true;
     }
     throw new GeneralException('There was a problem creating this role. Please try again.');
 }
开发者ID:qloog,项目名称:laravel5-backend,代码行数:32,代码来源:RoleRepositoryEloquent.php

示例4: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //
     //        $u1 = \App\User::create(
     //            ['name'=>'super_admin', 'email'=>'super_admin@oa.com', 'password'=>Hash::make('123456')]
     //        );
     $user = \App\User::where('email', '=', 'super_admin@oa.com')->first();
     echo $user . "\n";
     //        $role = new \App\Models\Role();
     //        $role->name         = 'SuperUser';
     //        $role->display_name = '超级管理员'; // optional
     //        $role->description  = '网站超管'; // optional
     //        $role->save();
     $role = \App\Models\Role::where('name', '=', 'SuperUser')->first();
     echo $role . "\n";
     //
     //        $user->attachRole($role);
     //
     $permission = new \App\Models\Permission();
     $permission->name = 'create-post';
     $permission->display_name = 'Create Posts';
     // optional
     $permission->description = 'create new blog posts';
     // optional
     $permission->save();
     $role->attachPermission($permission);
 }
开发者ID:jin-yc10,项目名称:oa-test,代码行数:32,代码来源:SuperUserSeeder.php

示例5: postLogin

 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request)
 {
     // Auth::logout();
     if (Auth::check()) {
         return redirect('/posts');
     }
     // return view('login.login');
     $username = $request->username;
     $password = $request->password;
     $field = filter_var($username, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
     $pass = 'Password';
     if (Auth::attempt([$field => $username, 'password' => $password])) {
         $user = Auth::user();
         $role = Role::where('userId', $user->objectId)->first();
         if ($role && $role->name == 'Admin') {
             return redirect('/posts');
         } else {
             Auth::logout();
             Session::flash('error', 'You are not admin right.');
             return redirect('/administration')->with(['error' => 'You are not admin right.']);
         }
     } else {
         Session::flash('error', 'Username or Password is wrong.');
         return redirect('/administration')->with(['error' => 'Username or Password is wrong.']);
     }
 }
开发者ID:SawMaineK,项目名称:iwomenapp,代码行数:31,代码来源:LoginController.php

示例6: store

 /**
  * Store a newly created ShareUser in storage.
  * POST /shareUsers
  *
  * @param Request $request
  *
  * @return Response
  */
 public function store(Request $request)
 {
     if (sizeof(ShareUser::$rules) > 0) {
         $validator = $this->validateRequestOrFail($request, ShareUser::$rules);
         if ($validator) {
             return $validator;
         }
     }
     $input = $request->all();
     $user = User::where('id', $input['user_id'])->first();
     if ($user) {
         $shared_with_other_account = User::where('phoneNo', $user->phoneNo)->lists('id');
         if (count($shared_with_other_account) > 0) {
             $alreadyShared = ShareUser::where('share_objectId', $input['share_objectId'])->wherein('user_id', $shared_with_other_account)->get();
             if (count($alreadyShared) > 0) {
                 return response()->json("The share object id has already been taken.", 403);
             }
         }
         $shareUsers = $this->shareUserRepository->create($input);
         $shared_user = User::where('objectId', $shareUsers->share_objectId)->first();
         if ($shared_user) {
             $shared_user->points += 10;
             $shared_user->update();
             $user->shared = true;
             $user->update();
             $role = Role::where('userId', $user->objectId)->first();
             if ($role) {
                 $user['role'] = $role->name;
             } else {
                 $user['role'] = 'User';
             }
         }
         return $this->sendResponse($user->toArray(), "ShareUser saved successfully");
     }
 }
开发者ID:SawMaineK,项目名称:iwomenapp,代码行数:43,代码来源:ShareUserAPIController.php

示例7: __construct

 public function __construct()
 {
     $role = Role::where('name', 'user')->first();
     $this->middleware('auth');
     $this->middleware('session');
     $this->authorize('auth', $role);
 }
开发者ID:mauhftw,项目名称:mizustats,代码行数:7,代码来源:ProfileController.php

示例8: save

 /**
  * Save the User.
  *
  * @param  App\Models\User $user
  * @param  Array  $inputs
  * @return void
  */
 private function save($user, $inputs)
 {
     if (isset($inputs['seen'])) {
         $user->seen = $inputs['seen'] == 'true';
     } else {
         $user->username = $inputs['username'];
         $user->email = $inputs['email'];
         if (isset($inputs['role'])) {
             $user->role_id = $inputs['role'];
         } else {
             $role_user = $this->role->where('slug', 'user')->first();
             $user->role_id = $role_user->id;
         }
     }
     $user->save();
 }
开发者ID:melvinmmw,项目名称:laravel5-example,代码行数:23,代码来源:UserRepository.php

示例9: __construct

 public function __construct()
 {
     $role = Role::where('name', 'admin')->first();
     //Mejor guardar el role en la session
     $this->middleware('auth');
     $this->authorize('auth', $role);
     $this->middleware('session');
 }
开发者ID:mauhftw,项目名称:mizustats,代码行数:8,代码来源:AdminReportsController.php

示例10: checkRole

 public function checkRole($id)
 {
     $role = Role::where('userId', $id)->first();
     if ($role) {
         return response()->json($role->name);
     }
     return response()->json('User');
 }
开发者ID:SawMaineK,项目名称:iwomenapp,代码行数:8,代码来源:UserAPIController.php

示例11: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user = new \App\Models\User();
     $user->email = "admin@success.local";
     $user->password = \Hash::make("admin");
     $user->save();
     $role = \App\Models\Role::where("key", "=", "admin")->first();
     $user->roles()->attach($role->id);
 }
开发者ID:clubttt,项目名称:SuccessModel4,代码行数:14,代码来源:AdminSeeder.php

示例12: destroyRole

 /**
  * Locate role, detach from perms and users then delete.
  *
  * @param $name
  */
 protected static function destroyRole($name)
 {
     $roleActiveDirectoryInspector = Role::where('name', $name)->first();
     if ($roleActiveDirectoryInspector) {
         $roleActiveDirectoryInspector->perms()->detach();
         $roleActiveDirectoryInspector->users()->detach();
         Role::destroy($roleActiveDirectoryInspector->id);
     }
 }
开发者ID:sroutier,项目名称:l51esk-modules,代码行数:14,代码来源:MaintenanceTrait.php

示例13: authorize

 public static function authorize()
 {
     $val = 0;
     $role = \App\Models\Role::where('id', Auth::user()->role_id)->first();
     if ($role) {
         $val = $role->authorize;
     }
     return $val;
 }
开发者ID:suhe,项目名称:bdoportal,代码行数:9,代码来源:User.php

示例14: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $roles = ['Normal User', 'Pro User', 'Admin', 'Free'];
     foreach ($roles as $r) {
         $role = Role::where('name', '=', $r)->first();
         if (!$role) {
             Role::create(['name' => $r]);
         }
     }
 }
开发者ID:bradsmithcan,项目名称:laravel_infusionsoft_constantcontact,代码行数:15,代码来源:RoleTableSeeder.php

示例15: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if (Role::get()->count() == 0) {
         Role::create(['name' => 'admin', 'display_name' => 'Admin', 'description' => 'User can adminstrate the site']);
         Role::create(['name' => 'user', 'display_name' => 'User', 'description' => 'User can navigate the site']);
     }
     if (User::get()->count() == 0) {
         User::create(['name' => env('ROOT_USER_NAME', 'Test User'), 'email' => env('ROOT_USER_EMAIL', 'testuser@test.com'), 'password' => Hash::make(env('ROOT_USER_PASSWORD', 'password'))])->attachRole(Role::where('name', '=', 'admin')->first());
     }
 }
开发者ID:nich-mctishe,项目名称:laravel-framework,代码行数:15,代码来源:UsersTableSeeder.php


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