tonyniu's avatar

How to cast Illuminate\Support\Collection to \Illuminate\Database\Eloquent\Collection

really confused about the class naming on the 'support' folder, always have the same name with other classes.

Now what I am trying to do is:

$some = (\Illuminate\Database\Eloquent\Collection::make(Session::get('cart')['wishlist']))::all();

I tried to cast the class to \Illuminate\Database\Eloquent\Collection, but always get an error like this:Non-static method Illuminate\Support\Collection::get() should not be called statically

What I should do then? thanks

0 likes
4 replies
tonyniu's avatar

sorry more info, Session::get('cart')['wishlist'] should return a Collection object, which should be \Illuminate\Database\Eloquent\Collection instead of lluminate\Support\Collection

tonyniu's avatar

problem solved, $collection = Collection::make($some['wishlist']); and then call $collection->first()...

really have no idea why.....

1 like
Sam T.'s avatar

@tonyniu that still only returns the first collection in the parent collection. What if you want to return all subsequent sub-collections as an Eloquent Collection?

Please or to participate in this conversation.