Creating an empty collection of Eloquent model #32850
-
|
I've assumed that How to get empty collection of instances? My workaround is |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
|
You need to pass an array to the collect([new App\Work]); |
Beta Was this translation helpful? Give feedback.
-
|
Nope, it doesn't work:
|
Beta Was this translation helpful? Give feedback.
-
|
So just |
Beta Was this translation helpful? Give feedback.
collectspecifically returns an instance ofIlluminate\Support\Collection.You want an instance of
Illuminate\Database\Eloquent\Collection.So just
$collection = new \Illuminate\Database\Eloquent\Collection();