last record in laravel
xxxxxxxxxx
Model::orderBy ('id', 'DESC')->first();
never use latest when multiple data have same created_at time
xxxxxxxxxx
Model::latest()->first(); // retrieves the last element
Model::orderBy('id', 'desc')->first(); // retrieves all, sort it and get the first
xxxxxxxxxx
$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'));