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


PHP User::whereHas方法代码示例

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


在下文中一共展示了User::whereHas方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: admins

 public function admins()
 {
     $admins = User::whereHas('roles', function ($q) {
         $q->where('name', 'web');
     })->get();
     return $admins;
 }
开发者ID:scify,项目名称:city-r-us-service,代码行数:7,代码来源:UserService.php

示例3: findActiveTalents

 /**
  * Returns a paginated list of all active talents
  *
  * @param null $tag
  * @param null $skill
  * @param null $location
  * @param null $orderBy
  * @param int $perPage
  * @param null $profession
  * @return \Illuminate\Pagination\Paginator
  */
 public function findActiveTalents($tag = null, $skill = null, $location = null, $orderBy = null, $perPage = 12, $profession = null)
 {
     $results = User::whereHas('profile', function ($q) use($tag, $skill, $location, $orderBy, $profession) {
         $q->where('published', '=', true);
         if ($location) {
             $q->where('location', '=', $location);
         }
         if ($tag) {
             $q->whereHas('tags', function ($q2) use($tag) {
                 $q2->where('tags.name', '=', $tag);
             });
         }
         if ($skill) {
             $q->whereHas('skill', function ($q) use($tag, $skill) {
                 $q->where('id', '=', $skill);
             });
         }
         if ($profession) {
             $q->where('profession_id', '=', $profession);
         }
     })->with('ratings')->with('profile');
     if ($orderBy) {
         $results->orderBy($orderBy);
     } else {
         $results->orderBy('id', 'DESC');
     }
     $paginatedResults = $results->paginate($perPage);
     if ($skill or $tag) {
         $paginatedResults->appends(['needs' => $skill, 'tag' => $tag]);
     }
     return $paginatedResults;
 }
开发者ID:katzumi,项目名称:talent4startups,代码行数:43,代码来源:UserRepository.php

示例4: handle

 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     // Set the inquiry model data.
     $this->inquiry->user_id = auth()->id();
     $this->inquiry->uuid = uuid();
     $this->inquiry->category_id = $this->category->id;
     $this->inquiry->title = $this->request->input('title');
     $this->inquiry->description = $this->request->input('description');
     if ($this->category->manager === true) {
         // If the category requires manager approval, we'll retrieve the manager record.
         $manager = User::whereHas('roles', function (Builder $query) {
             $query->whereName('managers');
         })->findOrFail($this->request->input('manager'));
         $this->inquiry->manager_id = $manager->id;
         // We'll send the manager a notification.
         $notification = new Notification($manager, 'emails.inquiries.created', ['inquiry' => $this->inquiry], function (Message $message) use($manager) {
             $message->subject('A New Request Requires Your Approval');
             $message->to($manager->email);
         });
     }
     if ($this->inquiry->save()) {
         // If the inquiry was successfully created, we'll
         // send out the notification if one has been set.
         if (isset($notification)) {
             $this->dispatch($notification);
         }
         return true;
     }
     return false;
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:35,代码来源:Store.php

示例5: destroy

 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @throws CannotRemoveRolesException
  *
  * @return int
  */
 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 (Builder $builder) use($adminName) {
         $builder->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->getKey() === auth()->user()->getKey() && count($administrators) === 1) {
         throw new CannotRemoveRolesException("Unable to remove the administrator role from this user. You're the only administrator.");
     }
     return $role->users()->detach($user);
 }
开发者ID:stevebauman,项目名称:administration,代码行数:31,代码来源:RoleUserProcessor.php

示例6: apiGetResearcher

 public function apiGetResearcher(Request $request, $keyword = null)
 {
     /* @var Role $researchers */
     $researchers = Role::where("key", "=", "researcher")->first();
     if ($keyword == null) {
         $users = $researchers->users()->get();
     } else {
         $users = User::whereHas("roles", function ($query) {
             $query->where('key', '=', 'researcher');
         })->where("firstname", "LIKE", "%{$keyword}%")->orWhere("lastname", "LIKE", "%{$keyword}%")->get();
     }
     return $users;
 }
开发者ID:pchaow,项目名称:SuccessModel5,代码行数:13,代码来源:UserController.php

示例7: handle

 /**
  * Execute the job.
  *
  * @throws CannotRemoveRolesException
  *
  * @return bool
  */
 public function handle()
 {
     $this->user->name = $this->request->input('name', $this->user->name);
     $this->user->email = $this->request->input('email');
     $password = $this->request->input('password');
     // Verify before changing the users password that it's not empty.
     if (!empty($password)) {
         // If the user doesn't have a set password mutator,
         // we'll encrypt the password.
         if (!$this->user->hasSetMutator('password')) {
             $password = bcrypt($password);
         }
         $this->user->password = $password;
     }
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     $roles = $this->request->input('roles', []);
     // Retrieve all administrator users.
     $administrators = $this->user->whereHas('roles', function (Builder $builder) use($adminName) {
         $builder->whereName($adminName);
     })->get();
     // Retrieve the administrator role.
     $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 (count($roles) === 0 && $this->user->hasRole($admin) && $this->user->getKey() === auth()->user()->getKey() && count($administrators) === 1) {
         throw new CannotRemoveRolesException("Unable to remove the administrator role. You're the only administrator.");
     }
     if ($this->user->save()) {
         $this->user->roles()->sync($roles);
         return true;
     }
     return false;
 }
开发者ID:stevebauman,项目名称:administration,代码行数:43,代码来源:Update.php

示例8: findOrCreateByVk

 public function findOrCreateByVk($data) : User
 {
     $user = User::whereHas('connections', function ($query) use($data) {
         $query->where('driver', 'vk');
         $query->whereRaw('cast(("socials".data->>\'id\') as varchar) = ?', [$data->id]);
     })->first();
     if (!empty($user)) {
         return $user;
     }
     $user = User::whereIn('username', [$data->nickname, $data->email])->first();
     if (!empty($user)) {
         $this->addConnection($user, 'vk', $data);
         return $user;
     }
     /** @var User $user */
     $user = User::create(['first_name' => $data->user['first_name'], 'last_name' => $data->user['last_name'], 'username' => $data->nickname ?? $data->email, 'avatar' => $data->avatar]);
     $this->addConnection($user, 'vk', $data);
     return $user;
 }
开发者ID:rodnover55,项目名称:guess-rock,代码行数:19,代码来源:UsersService.php

示例9: boot

 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     $author = User::whereHas('role', function ($q) {
         $q->where('slug', 'admin');
     })->first();
     $categories = Category::where('is_active', 1)->get();
     $postsRecents = Post::where('is_active', 1)->where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get();
     $postsPopular = Post::where('is_active', 1)->where('seen', 1)->orderBy('nview', 'desc')->take(3)->get();
     $commentsRecents = Comment::where('seen', 1)->orderBy('created_at', 'desc')->take(3)->get();
     $tags = Tag::all();
     $INFO_SITE = Admin::first();
     view()->share('author', $author);
     view()->share('categories', $categories);
     view()->share('tags', $tags);
     view()->share('postsRecents', $postsRecents);
     view()->share('postsPopular', $postsPopular);
     view()->share('commentsRecents', $commentsRecents);
     view()->share('INFO_SITE', $INFO_SITE);
 }
开发者ID:doankhoi,项目名称:Application,代码行数:24,代码来源:AppServiceProvider.php

示例10: queryRelation

 /**
  * 关联查询
  *
  *  article 为 User 模型 里面的 article() 方法
  *
  */
 public function queryRelation()
 {
     //select `username` from `tcc_users` where (select count(*) from `article` where `article`.`user_id` = `tcc_users`.`id`) > 5
     $user = User::has('article', '>', 5)->select('username')->get();
     debug($user);
     $user = User::whereHas('article', function ($query) {
         $query->where('content', 'like', '%content%');
     })->get();
     debug($user);
     return view('index');
 }
开发者ID:tccLaravel,项目名称:learn,代码行数:17,代码来源:RelationshipsController.php

示例11: getAllStats

 public function getAllStats()
 {
     $users = User::whereHas('roles', function ($q) {
         $q->where('name', 'hacker');
     })->with('application', 'application.school')->get();
     $gender = array();
     $grad_year = array();
     $school = array();
     $completed = array(0, 0);
     foreach ($users as $user) {
         if ($user->application->completed) {
             if (!isset($gender[$user->application->gender])) {
                 $gender[$user->application->gender] = 1;
             } else {
                 $gender[$user->gender]++;
             }
             if (!isset($grad_year[$user->application->grad_year])) {
                 $grad_year[$user->application->grad_year] = 1;
             } else {
                 $grad_year[$user->application->grad_year]++;
             }
             if (!isset($school[$user->application->school])) {
                 $school[$user->application->school] = 1;
             } else {
                 $school[$user->application->school]++;
             }
             $completed[1]++;
         } else {
             $completed[0]++;
         }
     }
     var_dump($gender);
     var_dump($grad_year);
     // var_dump($school);
     var_dump($completed);
 }
开发者ID:BoilerMake,项目名称:backend,代码行数:36,代码来源:ExecController.php

示例12: sortUser

 public function sortUser($slug)
 {
     $users = User::whereHas('role', function ($q) use($slug) {
         $q->where('slug', $slug);
     })->orderBy('seen', 'asc')->orderBy('created_at', 'desc')->paginate($this->itemPerPage);
     $roles = Role::all();
     $counts['total'] = User::count();
     foreach ($roles as $role) {
         $slug = $role->slug;
         $counts[$slug] = User::whereHas('role', function ($q) use($slug) {
             $q->whereSlug($slug);
         })->count();
     }
     return view('admin.users.index', compact('users', 'roles', 'counts'));
 }
开发者ID:doankhoi,项目名称:Application,代码行数:15,代码来源:UserController.php

示例13: getDaftarGuruInstansi

 public function getDaftarGuruInstansi($instansiId = null)
 {
     if ($instansiId == null) {
         return '';
     }
     $data = ['guru' => User::whereHas('guru', function ($query) use($instansiId) {
         return $query->where('instansi_id', $instansiId);
     })->get()];
     return view('backend.pages.undangan.guru-instansi', $data);
 }
开发者ID:htwibowo,项目名称:simonev,代码行数:10,代码来源:GelombangController.php

示例14: form

 /**
  * Returns a new form for the specified inquiry.
  *
  * @param Inquiry  $inquiry
  * @param Category $category
  *
  * @return \Orchestra\Contracts\Html\Builder
  */
 public function form(Inquiry $inquiry, Category $category)
 {
     return $this->form->of('inquiries', function (FormGrid $form) use($inquiry, $category) {
         if ($inquiry->exists) {
             $method = 'PATCH';
             $url = route('inquiries.update', [$inquiry->id]);
             $form->submit = 'Save';
         } else {
             $method = 'POST';
             $url = route('inquiries.store', [$category->id]);
             $form->submit = 'Create';
         }
         $form->attributes(compact('method', 'url'));
         $form->with($inquiry);
         $form->fieldset(function (Fieldset $fieldset) use($inquiry, $category) {
             $fieldset->control('input:text', 'title')->attributes(['placeholder' => 'Enter the title of your request.']);
             if ($category->manager) {
                 $fieldset->control('input:select', 'manager', function (Field $field) use($inquiry) {
                     $field->label = 'Manager';
                     $field->options = User::whereHas('roles', function (Builder $query) {
                         $query->whereName('Managers');
                     })->orderBy('name')->pluck('name', 'id');
                     $field->value = function (Inquiry $inquiry) {
                         return $inquiry->manager_id;
                     };
                     if ($inquiry->category_id) {
                         $field->attributes = ['disabled'];
                     }
                 });
             }
             $fieldset->control('input:textarea', 'description')->attributes(['placeholder' => 'Enter the description of your request.']);
         });
     });
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:42,代码来源:InquiryPresenter.php


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