/** * Run the database seeds. * * @return void */ public function run() { $users = $this->userRepository->findAll(); for ($i = 0; $i < 100; $i++) { $comment = Comment::inRandomOrder()->first(); Comment::instantiate($users->random(), $comment, ['body' => $this->faker->text]); } $comments = Comment::all(); foreach ($comments as $comment) { $comment->refreshScore(); } }
/** * Run the database seeds. * * @return void */ public function run() { $users = $this->userRepository->findAll(); $tags = Tag::get(['id'])->pluck('id')->toArray(); for ($i = 0; $i < 20; $i++) { $user = $users->random(); $count = mt_rand(1, 2); $post = Post::instantiate($user, ['title' => $user->name . '的好贴'], $this->faker->randomElements($tags, $count)); Comment::instantiate($user, $post, ['body' => $this->faker->text, 'views' => $this->faker->numberBetween(0, 1000)]); } Post::inRandomOrder()->first()->makeSticky(); }
public function store(CommentRequest $request, Comment $comment) { $comment = Comment::instantiate($this->user(), $comment, $request->all()); $this->flashCommentId($comment); return $this->success('submit'); }