Answers for "laravel 8 grab last record"

PHP
6

laravel get last record

Model::latest()->first();
Posted by: Guest on May-06-2020
0

laravel get second last record

$row = News::count();
        $newsid = $row -2;
        $news1 = News::all()->last();
        $news2 = News::orderBy('created_at', 'desc')->skip($newsid)->take($newsid)->first();
        return view('user/start', compact('news1', 'news2', 'newsid'));
Posted by: Guest on May-26-2020

Browse Popular Code Answers by Language