Tuesday, March 21, 2017

Laravel Eloquent `take` and `orderBy`

When I try to use each of "take" and "orderBy" query, the Model return some records:

$this->hasMany("App\User")->take(3)

$this->hasMany("App\User")->orderBy("id", "desc")

But when I combine them, it return a null array:

$this->hasMany("App\User")->take(3)->orderBy("id", "desc")

I run the original sql (from toSql() function) and it return 3 records as I expect. What mistake I get?



via Einsamer

Advertisement