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


PHP User::whereHas方法代码示例

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


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

示例1: getUsersByRole

 public function getUsersByRole($role)
 {
     $users = User::whereHas('userRole', function ($q) use($role) {
         return $q->where('user_role_name', $role);
     })->get()->toArray();
     return $users;
 }
开发者ID:arsenaltech,项目名称:folio,代码行数:7,代码来源:UserRepository.php

示例2: index

 public function index()
 {
     $season = $_REQUEST['season'] ?: $this->season;
     $activity = $_REQUEST['activity'] ?: 'Poker';
     $venue_id = $_REQUEST['venue_id'] ?: League::where('season', $season)->where('activity', $activity)->value('venue_id');
     $league = League::where('season', $season)->where('activity', $activity)->where('venue_id', $venue_id)->first();
     if (!$league->id) {
         $_SESSION['ALERT'] = alert("No League Found!", "There were no leagues found matching the specified parameters.", "warning");
         return sizeof($_REQUEST) ? redirect("/rankings") : redirect("/");
     }
     $rankings_query = ' select s.player_id as id, concat(p.lastname, ", ", p.forename) as name, concat(p.forename, " ", p.lastname) as fullname, count(*) as games, sum(s.points) as total ';
     $rankings_query .= ' from t_scores s ';
     $rankings_query .= ' join t_events e on e.id = s.event_id ';
     $rankings_query .= ' join t_players p on p.id = s.player_id ';
     $rankings_query .= ' where e.league_id=? ';
     $rankings_query .= ' group by s.player_id ';
     $rankings = DB::select($rankings_query, [$league->id]);
     $points_query = ' select points ';
     $points_query .= ' from t_scores ';
     $points_query .= ' where player_id=? ';
     $points_query .= ' and event_id in ( ';
     $points_query .= ' select id ';
     $points_query .= ' from t_events ';
     $points_query .= ' where league_id=? ';
     $points_query .= ' ) ';
     $points_query .= ' order by points desc ';
     $points_query .= ' limit ' . $league->ranked_at;
     array_walk($rankings, function (&$ranking) use($points_query, $league) {
         $ranking->points = DB::select($points_query, [$ranking->id, $league->id]);
         $ranking->points = array_map(function ($p) {
             return $p->points;
         }, $ranking->points);
         $ranking->value = $ranking->games >= $league->ranked_at ? $league->ranking == 'AVG' ? floor(array_sum($ranking->points) / $league->ranked_at) : array_sum($ranking->points) : -1;
     });
     $ranked = array_filter($rankings, function ($ranking) {
         return $ranking->value !== -1;
     });
     usort($ranked, function ($a, $b) {
         return $b->value - $a->value;
     });
     $unranked = array_filter($rankings, function ($ranking) {
         return $ranking->value === -1;
     });
     usort($unranked, function ($a, $b) {
         return $b->total - $a->total;
     });
     $seasonPointsLeaders = array_filter($rankings, function ($ranking) {
         return $ranking->total > 0;
     });
     usort($seasonPointsLeaders, function ($a, $b) {
         return $b->total - $a->total;
     });
     $seasonPointsLeaders = array_slice($seasonPointsLeaders, 0, 1);
     $wildCardWinners = User::whereHas('scores', function ($query) use($league) {
         $query->where('finished', '1')->whereHas('event', function ($query) use($league) {
             $query->where('league_id', $league->id)->where('week_num', 'Wild Card');
         });
     })->get();
     return view('pages.rankings', compact('league', 'ranked', 'unranked', 'seasonPointsLeaders', 'wildCardWinners'));
 }
开发者ID:MadeByGlutard,项目名称:GreenMountainGaming.com,代码行数:60,代码来源:RankingsController.php

示例3: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $auctions = Auction::all();
     foreach ($auctions as $auction) {
         $enddate = new DateTime($auction->enddate);
         $now = new Datetime();
         if ($enddate < $now) {
             $highest_bid = $auction->highest_bid;
             $auction_id = $auction->id;
             $highest_bidder = User::whereHas('bids', function ($q) use($highest_bid, $auction_id) {
                 $q->where('amount', '=', $highest_bid)->where('auction_id', '=', $auction_id);
             })->first();
             if ($highest_bidder) {
                 $bidders = User::whereHas('bids', function ($q) use($highest_bid, $auction_id) {
                     $q->where('auction_id', $auction_id)->where('amount', '>', $highest_bid);
                 })->get();
                 foreach ($bidders as $bidder) {
                     $this->info($auction->title . ' was not sold to ' . $bidder->email);
                     Mail::send('mails.loser', ['user' => $bidder], function ($ms) use($bidder) {
                         $ms->to($bidder->email, $bidder->company)->subject('Too bad!');
                     });
                 }
                 Mail::send('mails.winner', ['user' => $highest_bidder], function ($ms) use($highest_bidder) {
                     $ms->to($highest_bidder->email, $highest_bidder->company)->subject('Congratulations!');
                 });
                 $this->info($auction->title . ' was sold to ' . $highest_bidder->company);
             } else {
                 $auction->active = false;
                 $auction->expired = true;
                 $auction->save();
                 $this->info($auction->title . ' is expired.');
             }
         }
     }
 }
开发者ID:kristofsw,项目名称:landoretti-webdev,代码行数:40,代码来源:RefreshAuctions.php

示例4: mapa

 public function mapa()
 {
     $vendedores = User::whereHas('PerfilUsuario', function ($query) {
         $query->where('tipo', '=', 'Vendedor');
     })->with('PerfilUsuario')->get();
     return view('Vendedor.Mapa')->with('vendedores', $vendedores);
 }
开发者ID:renanpupin,项目名称:brasilspot,代码行数:7,代码来源:VendedorController.php

示例5: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     //listing all farmer when no search is done
     $allfarmer = User::where('user_type_id', 3)->paginate(10);
     //$allfarmer = User::where('user_type_id', 3)->get(); /previous code
     //listing Farmerpoint for dropdown
     $farmerPointList = FarmerPoint::Lists('name', 'id');
     $cropList = Crop::Lists('name', 'id');
     //recieving data from search field
     $farmer_name = $request->input('name');
     $farmer_phone = $request->input('phone');
     $farmerInPoint = $request->input('id');
     $farmerWithCrop = $request->input('crop');
     if (!empty($farmer_name)) {
         $allfarmer = User::where('user_type_id', 3)->where('name', 'LIKE', '%' . $farmer_name . '%')->paginate(10);
     }
     if (!empty($request->phone)) {
         $allfarmer = User::where('user_type_id', 3)->where('phone', 'LIKE', '%' . $farmer_phone . '%')->paginate(10);
     }
     if (!empty($farmerInPoint)) {
         if (!empty($farmerWithCrop)) {
             $allfarmer = User::whereHas('farmerCrop', function ($query) use($farmerWithCrop) {
                 $query->where('crop_id', $farmerWithCrop);
             })->where('user_type_id', 3)->where('farmer_point_id', $farmerInPoint)->paginate(10);
         } else {
             $allfarmer = User::where('user_type_id', 3)->where('farmer_point_id', $farmerInPoint)->paginate(10);
         }
     }
     if (!empty($farmerWithCrop)) {
         $allfarmer = User::whereHas('farmerCrop', function ($query) use($farmerWithCrop) {
             $query->where('crop_id', $farmerWithCrop);
         })->where('user_type_id', 3)->paginate(10);
     }
     return view('farmer.FarmerList', ['allfarmer' => $allfarmer, 'farmerPointList' => $farmerPointList, 'cropList' => $cropList]);
 }
开发者ID:TawsifKarim,项目名称:farmerspoint,代码行数:40,代码来源:farmerController.php

示例6: getAssignedUsersToGroup

 public function getAssignedUsersToGroup($groupId)
 {
     $users = User::whereHas('groups', function ($q) use($groupId) {
         $q->where('group_id', $groupId);
     })->where('role', '<', 2)->paginate(5);
     return $users;
 }
开发者ID:jtrupina,项目名称:mobile-app-challenge-2015-web,代码行数:7,代码来源:UserRepository.php

示例7: postAddUserAsFriend

 public function postAddUserAsFriend($username)
 {
     $user = User::whereHas('profile', function ($q) use($username) {
         $q->whereUsername($username);
     })->first();
     $user->friends()->attach(auth()->user());
     redirect()->to('/');
 }
开发者ID:Armen2004,项目名称:laravel-network,代码行数:8,代码来源:UsersController.php

示例8: testUserRestore

 public function testUserRestore()
 {
     $UserAdmin = \App\User::whereHas('role', function ($q) {
         $q->where('admin', true);
     })->first();
     $this->be($UserAdmin);
     $User = \App\User::create(['email' => str_random(5) . '@' . str_random(3) . '.com']);
     $id = $User->id;
     $User = \App\User::withTrashed()->where('id', $id)->first();
     $this->call('GET', route('admin.users.restore', $User->id));
     $User->forceDelete();
     $this->assertRedirectedToRoute('admin.users.list');
 }
开发者ID:DJZT,项目名称:tezter,代码行数:13,代码来源:AdminUsersTest.php

示例9: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $start = Carbon::createFromTimeStamp(Input::get('start'), 'America/Chicago');
     $end = Carbon::createFromTimeStamp(Input::get('end'), 'America/Chicago');
     //All Timecards for the period
     $timecards = \App\Timecard::with('user')->timecardsForPeriod($start, $end)->get();
     return $timecards;
     //Users with at least 1 timecard for period
     $users = \App\User::whereHas('timecards', function ($q) use($timecards) {
         $q->whereIn('id', $timecards);
     })->with('timecards')->get();
     //must do this to remove extra timecards included with wherehas statement
     return $this->groupTimecardsByUser($users, $timecards);
 }
开发者ID:sodapopinsky,项目名称:teamifyDev,代码行数:19,代码来源:TimecardsController.php

示例10: users

 public static function users($company_id, $start, $end)
 {
     if ($company_id == null) {
         return null;
     }
     $arr = [];
     $users = User::whereHas('company', function ($q) use($company_id) {
         $q->where('companies.id', $company_id);
     })->with('info')->get();
     foreach ($users as $user) {
         array_push($arr, self::singleUser($user, $start, $end, $company_id));
     }
     return $arr;
 }
开发者ID:svetlinyotov,项目名称:Timeline_v2.0,代码行数:14,代码来源:Payment.php

示例11: statistics

 public function statistics()
 {
     $users = User::whereHas('trials', function ($query) {
         $query->where('complete', true);
     })->get();
     $totalUsers = $users->count();
     $totalTrials = Trial::whereComplete(true)->count();
     $totalHits = Trial::whereComplete(true)->has('hits', '>', 0)->count();
     $totalSelections = Selection::whereHas('trial', function ($query) {
         $query->where('complete', true);
     })->count();
     $totalChoices = $totalTrials * 5;
     $targets = Target::has('expiredExperiment')->get();
     //        $targets = Target
     return view('pages.statistics')->with(compact('totalUsers', 'totalTrials', 'totalHits', 'totalSelections', 'totalChoices', 'targets'));
 }
开发者ID:acuccia,项目名称:remote-viewing,代码行数:16,代码来源:PagesController.php

示例12: getTypeUsers

 public function getTypeUsers(request $request, $type)
 {
     $users = User::whereHas('roles', function ($q) use($type) {
         $q->where('name', $type);
     })->orderby('id', 'DESC')->paginate(15);
     $output = array('users' => $users);
     return view('admin.users', $output);
 }
开发者ID:abhilash698,项目名称:kachingApp,代码行数:8,代码来源:AdminController.php

示例13: examinees

 public function examinees()
 {
     $user = auth()->user();
     if ($user->isExaminer()) {
         $quizzes = Quiz::with('tests')->where('user_id', $user->id)->lists('id');
         $examinees = User::whereHas('tests', function ($query) use($quizzes) {
             $query->whereIn('quiz_id', $quizzes);
         })->get();
     } else {
         if ($user->isExaminee()) {
             $examinees = User::where('id', $user->id)->get();
         } else {
             $examinees = User::has('tests')->get();
         }
     }
     return view('tests.examinees', compact('examinees'));
 }
开发者ID:akmuhammet,项目名称:quiz,代码行数:17,代码来源:TestController.php

示例14: teammate

 public function teammate()
 {
     $admins = User::whereHas('group', function ($q) {
         $q->where('group_id', 1);
     })->get();
     $mods = User::whereHas('group', function ($q) {
         $q->where('group_id', 2);
     })->get();
     $gms = User::whereHas('group', function ($q) {
         $q->where('group_id', 3);
     })->get();
     return view('main.teammate', compact('admins', 'mods', 'gms'));
 }
开发者ID:AdrianKuriata,项目名称:projekt,代码行数:13,代码来源:Controller.php

示例15: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     DB::table('results')->delete();
     DB::table('group_indicator')->delete();
     DB::table('group_user')->delete();
     DB::table('indicator_organization')->delete();
     DB::table('indicator_report')->delete();
     DB::table('report_user')->delete();
     DB::table('users')->delete();
     DB::table('organizations')->delete();
     DB::table('roles')->delete();
     DB::table('indicators')->delete();
     DB::table('groups')->delete();
     DB::table('reports')->delete();
     $roles = array(['name' => 'admin', 'display_name' => 'Admin'], ['name' => 'manager', 'display_name' => 'Manager'], ['name' => 'employee', 'display_name' => 'Employee']);
     foreach ($roles as $role) {
         Role::create($role);
     }
     $faker = Faker::create('pl_PL');
     $indicators = array(['name' => 'Wydane skierowania', 'function_name' => 'wyd_skier_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba skierowań wydanych przez pracownika w badanym okresie.'], ['name' => 'Obsłużone wizyty', 'function_name' => 'obsluz_wiz_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba wizyt obsłużonych przez pracownika w badanym okresie.'], ['name' => 'Udzielone ind. porady zawodowe', 'function_name' => 'ind_por_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba indywidualnych porad zawodowych udzielonych przez pracownika w badanym okresie.'], ['name' => 'Udzielone grupowe porady zawodowe', 'function_name' => 'grup_por_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba grupowych porad zawodowych udzielonych przez pracownika w badanym okresie.'], ['name' => 'Udzielone indywidualne inf. zawodowe', 'function_name' => 'ind_inf_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba indywidualnych informacji zawodowych udzielonych przez pracownika w badanym okresie.'], ['name' => 'Zorganizowane grupowe inf. zawodowe', 'function_name' => 'grup_inf_zaw_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba grupowych informacji zawodowych zorganizowanych przez pracownika w badanym okresie.'], ['name' => 'Badania kwest. do profilowania', 'function_name' => 'bad_kwest_prof_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba badań kwestionariuszem do profilowania przeprowadzonych przez pracownika w badanym okresie.'], ['name' => 'Sporządzone IPD', 'function_name' => 'sporz_ipd_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba indywidualnych planów działania sporządzonych przez pracownika w badanym okresie.'], ['name' => 'Zarejestrowani kontrahenci', 'function_name' => 'zarej_kontr_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba kontrahentów zarejestrowanych przez pracownika w badanym okresie.'], ['name' => 'Kontakty z kontrahentami', 'function_name' => 'kont_kontr_001', 'type' => 'value', 'default_coefficient' => 1, 'description' => 'Liczba kontaktów z kontrahentami zrealizowanych przez pracownika w badanym okresie.']);
     foreach ($indicators as $indicator) {
         Indicator::create($indicator);
     }
     $organizations = array(['code' => 'demo', 'name' => 'Powiatowy Urząd Pracy Demo', 'active' => true], ['code' => '24780', 'name' => 'Powiatowy Urząd Pracy w Zabrzu', 'active' => true]);
     foreach ($organizations as $organization) {
         $newOrganization = Organization::create($organization);
         foreach (Indicator::all() as $indicator) {
             $newOrganization->indicators()->attach($indicator->id, ['coefficient' => $faker->randomFloat(3, 0, 10)]);
         }
     }
     foreach (range(1, 50) as $index) {
         $organization = Organization::all()->random(1);
         $gender = $faker->randomElement(['male', 'female']);
         $lastName = $faker->lastName($gender);
         $user = User::create(['login' => $organization->code . '_' . $faker->numerify($lastName . '###'), 'name' => $faker->firstName($gender), 'surname' => $lastName, 'password' => Hash::make('secret'), 'active' => $faker->boolean(), 'organization_id' => $organization->id]);
         $role = Role::all()->random(1);
         $user->attachRole($role);
     }
     foreach (Organization::all() as $organization) {
         foreach (range(1, rand(5, 10)) as $index) {
             $group = Group::create(['organization_id' => $organization->id, 'name' => $faker->numerify('Grupa testowa ####')]);
             $users = $organization->users()->orderBy(DB::raw('random()'))->take(rand(5, 10))->get();
             foreach ($users as $user) {
                 $group->users()->attach($user->id);
             }
             $indicators = Indicator::all()->random(rand(3, 7));
             foreach ($indicators as $indicator) {
                 $group->indicators()->attach($indicator->id);
             }
         }
     }
     $managers = User::whereHas('roles', function ($role) {
         $role->where('name', 'manager');
     })->get();
     foreach ($managers as $manager) {
         foreach (range(1, rand(3, 6)) as $index) {
             $endDate = $faker->dateTimeThisDecade();
             $report = Report::create(['owner_id' => $manager->id, 'name' => $faker->numerify('Raport testowy ####'), 'start_date' => $faker->dateTimeThisDecade($endDate), 'end_date' => $endDate]);
             $indicators = Indicator::all()->random(rand(2, 5));
             foreach ($indicators as $indicator) {
                 $report->indicators()->attach($indicator->id, ['show_value' => $faker->boolean(), 'show_points' => $faker->boolean()]);
             }
             $users = $manager->organization->users()->orderBy(DB::raw('random()'))->take(rand(5, 10))->get();
             foreach ($users as $user) {
                 $report->users()->attach($user->id, ['view_self' => $faker->boolean(), 'view_all' => $faker->boolean()]);
             }
         }
     }
     Model::reguard();
 }
开发者ID:ppawlas,项目名称:swop,代码行数:76,代码来源:DemoSeeder.php


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