| @@ 7-31 (lines=25) @@ | ||
| 4 | ||
| 5 | use App\Models\Category; |
|
| 6 | ||
| 7 | class CategoriesController extends Controller |
|
| 8 | { |
|
| 9 | public function index() |
|
| 10 | { |
|
| 11 | $data = [ |
|
| 12 | 'categories' => Category::orderBy('name')->get(), |
|
| 13 | ]; |
|
| 14 | ||
| 15 | return view('frontend.categories.index', $data); |
|
| 16 | } |
|
| 17 | ||
| 18 | public function show($slug) |
|
| 19 | { |
|
| 20 | if (! $category = Category::findBySlug($slug)) { |
|
| 21 | abort(404); |
|
| 22 | } |
|
| 23 | ||
| 24 | $data = [ |
|
| 25 | 'category' => $category, |
|
| 26 | 'posts' => $category->posts()->published()->visible()->recentsFirst()->get(), |
|
| 27 | ]; |
|
| 28 | ||
| 29 | return view('frontend.categories.show', $data); |
|
| 30 | } |
|
| 31 | } |
|
| 32 | ||
| @@ 7-32 (lines=26) @@ | ||
| 4 | ||
| 5 | use App\Models\Post; |
|
| 6 | ||
| 7 | class PostsController extends Controller |
|
| 8 | { |
|
| 9 | public function index() |
|
| 10 | { |
|
| 11 | $data = [ |
|
| 12 | 'posts' => Post::published()->visible()->recentsFirst()->paginate(10), |
|
| 13 | ]; |
|
| 14 | ||
| 15 | return view('frontend.posts.index', $data); |
|
| 16 | } |
|
| 17 | ||
| 18 | public function show($slug) |
|
| 19 | { |
|
| 20 | $post = Post::findBySlug($slug); |
|
| 21 | ||
| 22 | if (! $post || $post->published_at->isFuture()) { |
|
| 23 | abort(404); |
|
| 24 | } |
|
| 25 | ||
| 26 | $data = [ |
|
| 27 | 'post' => $post, |
|
| 28 | ]; |
|
| 29 | ||
| 30 | return view('frontend.posts.show', $data); |
|
| 31 | } |
|
| 32 | } |
|
| 33 | ||