44 lines
1.3 KiB
PHP
44 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Channel;
|
|
use App\Models\Publication;
|
|
use Illuminate\Http\Response;
|
|
|
|
class PostController extends Controller
|
|
{
|
|
public function index(Channel $channel, string $prefix): Response
|
|
{
|
|
if (!$channel->prefixes->pluck('slug')->contains($prefix)) {
|
|
abort(404);
|
|
}
|
|
|
|
$publications = Publication::published()
|
|
->forChannel($channel)
|
|
->with(['post.author', 'taxonomyTerms'])
|
|
->latest('published_at')
|
|
->paginate(12);
|
|
|
|
return response()->view('theme::posts.index', compact('publications', 'prefix'));
|
|
}
|
|
|
|
public function show(Channel $channel, string $prefix, string $slug): Response
|
|
{
|
|
if ($prefix === $channel->taxonomy_slug) {
|
|
return app(TaxonomyController::class)->show($channel, $slug);
|
|
}
|
|
|
|
if (!$channel->prefixes->pluck('slug')->contains($prefix)) {
|
|
abort(404);
|
|
}
|
|
|
|
$publication = Publication::published()
|
|
->forChannel($channel)
|
|
->with(['blocks', 'taxonomyTerms', 'post.author'])
|
|
->where(fn ($q) => $q->where('slug', $slug)->orWhere('post_id', $slug))
|
|
->firstOrFail();
|
|
|
|
return response()->view('theme::posts.show', compact('publication', 'prefix'));
|
|
}
|
|
}
|