/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = User::all();
     Course::all()->each(function (Course $course) use($users) {
         $course->exams()->save(factory(Attachment::class)->make(['user_id' => $users->random()->getAttribute('id')]));
     });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = User::all();
     Course::all()->each(function (Course $course) use($users) {
         $course->comments()->saveMany(factory(Comment::class, mt_rand(2, 5))->make(['user_id' => $users->random()->getAttribute('id')]))->each(function (Comment $comment) use($users) {
             // 評論的評論
             $comment->comments()->save(factory(Comment::class)->make(['user_id' => $users->random()->getAttribute('id')]));
             // 評論按讚
             $likes = mt_rand(2, 5);
             $comment->likes()->saveMany(factory(Like::class, $likes)->make(['user_id' => $users->random()->getAttribute('id')]));
             $comment->update(['likes' => $likes]);
         });
     });
 }
Beispiel #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $users = User::all();
     $professors = Category::getCategories('professor');
     $dimensions = Category::getCategories('course.dimension');
     $generalDepartmentId = Category::getCategories('department', '通識中心', true);
     // 課程
     factory(Course::class, mt_rand(30, 80))->create()->each(function (Course $course) use($users, $professors, $dimensions, $generalDepartmentId) {
         // 通識課程
         if ($course->getAttribute('department_id') === $generalDepartmentId) {
             $course->dimension()->save($dimensions->random());
         }
         // 課程教授
         //$course->professors()->saveMany($professors->random(mt_rand(2, 3)));
     });
 }
Beispiel #4
0
 /**
  * @test
  */
 public function it_should_return_user_table_name()
 {
     $this->assertSame('users', User::getTableName());
 }
Beispiel #5
0
 /**
  * 轉移舊帳號.
  *
  * @param V1\SignUpRequest $request
  * @return bool
  */
 protected function transformOldAccount($request)
 {
     $user = User::where('username', $request->input('old_email'))->first();
     if (is_null($user)) {
         return false;
     } elseif (!Hash::check($request->input('old_password'), $user->getAttribute('remember_token'))) {
         return false;
     }
     $user->update(['username' => $request->input('username'), 'nickname' => $request->input('nickname')]);
     return true;
 }