當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Course::orderByRaw方法代碼示例

本文整理匯總了PHP中app\Course::orderByRaw方法的典型用法代碼示例。如果您正苦於以下問題:PHP Course::orderByRaw方法的具體用法?PHP Course::orderByRaw怎麽用?PHP Course::orderByRaw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Course的用法示例。


在下文中一共展示了Course::orderByRaw方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(User::class, 50)->create()->each(function ($user) {
         // store 10 rounds per user
         for ($i = 0; $i < 10; $i++) {
             // pick a random course to play on
             $course = Course::orderByRaw("random()")->first();
             // pick a random tee set on that course
             $teeSet = TeeSet::orderByRaw("random()")->where('course_id', $course->id)->first();
             $holes = $course->holes;
             $scores = [];
             // each round has 18 scores
             for ($j = 0; $j < 18; $j++) {
                 $scores[] = factory(Score::class)->make(['hole_id' => $holes[$j]->id]);
             }
             $round = factory(Round::class)->make(['tee_set_id' => $teeSet->id]);
             $round = $user->rounds()->save($round);
             $round->scores()->saveMany($scores);
         }
         $followed = [$user->id];
         // follow 10 random users
         for ($i = 0; $i < 10; $i++) {
             // pick a random user, that is not the current user and is not already followed
             $userToFollow = User::orderByRaw("random()")->whereNotIn('users.id', $followed)->first();
             $user->following()->attach($userToFollow);
             $followed[] = $userToFollow->id;
         }
     });
 }
開發者ID:robeasdon,項目名稱:golf-stat-tracker,代碼行數:34,代碼來源:UserSeeder.php


注:本文中的app\Course::orderByRaw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。