Skip to content

Commit

Permalink
add next / previous links to single posts
Browse files Browse the repository at this point in the history
  • Loading branch information
hellozach committed Aug 31, 2018
1 parent 2a16204 commit af46cc1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions resources/views/posts/single.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,14 @@
<h1>{{ $post->title }}</h1>

{!! $post->content !!}

<div class="d-flex justify-content-between mt-5">
@if($next)
<a href="{{ $next->path() }}">&larr; {{ $next->title }}</a>
@endif
@if($previous)
<a href="{{ $previous->path() }}">{{ $previous->title }} &rarr;</a>
@endif
</div>
</div>
@endsection
12 changes: 11 additions & 1 deletion src/Http/Controllers/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public function index()
*/
public function show(Post $post)
{
return view(config('gazette.posts.views.single'), compact('post'));
$next = Post::query()
->where('id', '>', $post->id)
->where('type', 'post')
->first();

$previous = Post::query()
->where('id', '<', $post->id)
->where('type', 'post')
->first();

return view(config('gazette.posts.views.single'), compact(['post', 'next', 'previous']));
}
}

0 comments on commit af46cc1

Please sign in to comment.