当前位置: 首页>>代码示例>>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;未经允许,请勿转载。