Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Say you have items [2,4,5,8,3] and you would like to get numbers around 5 which are 4 and 8.
how do you do it in laravel
thanks.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.6k views
Welcome To Ask or Share your Answers For Others

1 Answer

This solved my problem

   public function show(Blog $blog)
{
    $next = Blog::where('id', '>', $blog->id)
        ->oldest('id')
        ->first();
    $previous = Blog::where('id', '<', $blog->id)
        ->latest('id')
        ->first();
    return view('dashboard.Blog.show',compact('blog','previous','next'));
}

laravel-getting-the-previous-and-next-records


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...