Expand blog to 36 mirrored posts with deepened sections and page-turn links
Deploy Backend / deploy (push) Successful in 2m35s
Deploy Backend / deploy (push) Successful in 2m35s
- Six new topic pairs (EN+FA): TypeScript advanced patterns, SQL indexes, Git branching/reviews, TDD, clean architecture in Laravel, browser page load - Every existing post gains Key takeaways + FAQ sections in both languages - New engineering-practices category pair and database/git/testing tag pairs - Single-post API now returns same-language previous_post/next_post links
This commit is contained in:
1 parent
d659c5d325
commit
fbacb0c9a1
4 files changed
+1377
-9
No files matched your search
@@ -82,9 +82,43 @@ class PostController extends Controller
|
||||
->sortByDesc('published_at')
|
||||
->take(5);
|
||||
|
||||
// Plainly named page-turn links, always inside the reader's language so
|
||||
// the previous/next navigation never crosses the EN/FA mirror.
|
||||
$siblings = Post::with(['category', 'tags', 'author'])
|
||||
->byLanguage($postLang)
|
||||
->where('id', '!=', $post->id);
|
||||
|
||||
$previousPost = (clone $siblings)
|
||||
->where(
|
||||
fn ($q) => $q->where('published_at', '>', $post->published_at)
|
||||
->orWhere(
|
||||
fn ($q2) => $q2
|
||||
->where('published_at', '=', $post->published_at)
|
||||
->where('id', '>', $post->id)
|
||||
)
|
||||
)
|
||||
->orderByDesc('published_at')
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
|
||||
$nextPost = (clone $siblings)
|
||||
->where(
|
||||
fn ($q) => $q->where('published_at', '<', $post->published_at)
|
||||
->orWhere(
|
||||
fn ($q2) => $q2
|
||||
->where('published_at', '=', $post->published_at)
|
||||
->where('id', '<', $post->id)
|
||||
)
|
||||
)
|
||||
->orderBy('published_at')
|
||||
->orderBy('id')
|
||||
->first();
|
||||
|
||||
return response()->json([
|
||||
'post' => new PostResource($post),
|
||||
'related_posts' => PostResource::collection($relatedPosts),
|
||||
'previous_post' => $previousPost ? new PostResource($previousPost) : null,
|
||||
'next_post' => $nextPost ? new PostResource($nextPost) : null,
|
||||
], 200);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user