How to make json : previous, next on detail page

Posted 1 year 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.

Reply to

Use Markdown with GitHub-flavored code blocks.