當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。