How to make json : previous, next on detail page

Posted 11 months ago by mipusy

I want to previous and next links on detail page. My project is on laravel 5.5, vue.js.


public function show($id){

        $article = articles::with('tags')->find($id);

        $previous = articles::where('id', '<', $article->id)->orderBy('id','desc')->first();
        $next = articles::where('id', '>', $article->id)->orderBy('id','desc')->first();

        return Response()->json($article->with('previous', $previous)->with('next', $next));


Result is "{}". It doesn't work.

How should I write it?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.