/** * 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 compose(View $view) { $sticky_posts = \App\Modules\ForumModule\Entities\Post::withMeta()->sticky()->orderedByDate()->get(); $view->with('sticky_posts', $sticky_posts); }
public function delete(User $user, Post $post) { return $user->is($post->getAuthor()); }
public function index() { $posts = Post::withMeta()->orderedByScore()->paginate(10); return view('forum::posts.index', compact('posts')); }
/** * Execute the job. * * @return void */ public function handle() { $this->post->increment('views'); }