Home > Net >  laravel question: The latest Method not found
laravel question: The latest Method not found

Time:02-19

Route::get('/', function () {
    return view('posts', [
        'posts' => User::latest()->get()
    ]);
});

I can't use latest, because it says method not found.

CodePudding user response:

Try this

use App\Models\User;

Route::get('/', function () {
    return view('posts', [
        'posts' => User::latest()->get();
    ]);
});

CodePudding user response:

Make sure you use the User model correctly, like this:

use App\Models\User;

Route::get('/', function () {
    return view('posts', [
        'posts' => User::latest()->get();
    ]);
});
  • Related