mercredi 25 novembre 2015

Laravel 5 Using orderBy() with Models

So I can't for the life of me figure out why I can't use orderBy. I'm getting the error:

Call to undefined method Illuminate\Database\Eloquent\Collection::orderBy()

Here is my code:

Route::get('/teams', function(){
$page = 'Teams';
$teams = App\Team::all()->orderBy('teamFirstName')->get();
return view('teams')->with('page', $page)->with('allTeams', $teams);
});

I have tried removing the ->get(); I have tried using just Team::all. I'm using a Laravel cheat sheet and I seem to be following the Model syntax. I have also double checked that it is the right column name in my DB and have even tried using just id.

If I remove the ->orderBy() the query works fine and I can get all of the teams. So what am I doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire