I use laravel eloquent to get files of post that give me a collection
but I want an item from that collection by condition.
For example from that collection I want an item that type = 'product'
.
I am using foreach and check every item that have my condition and return it, but isn't any better way?
I tested collection method like contain but it return null
.
Files item have type filed that value is 'product' or 'blog'.
My code:
$post= Post::where('slug' , $slug)->first();
$cover = $post->files->contains(['type' , '=' , 'product']);
filter
method. It's in the documentation. – IGP$post->files
a relationship? – simonhamp