/** * Execute the job. * * @return void */ public function handle() { $comments = $this->comment->ancestorsAndSelf()->get(); foreach ($comments as $comment) { $comment->refreshScore(); } $this->comment->post->refreshScore(); }
/** * 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(); }
/** * Run the database seeds. * * @return void */ public function run() { $comments = Comment::all(); $users = $this->userRepository->findAll(); for ($i = 0; $i < 200; $i++) { $up = mt_rand(0, 1); if ($up) { $users->random()->voteUp($comments->random()); } else { $users->random()->voteDown($comments->random()); } } }
public function update(CommentRequest $request, Comment $comment) { $comment->fill($request->all())->save(); $this->flashCommentId($comment); return $this->success('edit'); }