Answer the question
In order to leave comments, you need to log in
How to use where on a collection in a loop?
Good afternoon. The bottom line is, there is a variable - it contains a collection of $clothes_col.
And there is another variable $categories_id - an array that stores id, for example 1,2,3.
If I use this code, I get an error that I requested 1 item, and I have 0 of them.
foreach($categories_id as $category){
$category += 0;
$category_clothe = $clothes_col->where('category_id', $category)->get()->random()->toArray();
print_r($category_clothe);
echo "<br />";
}
Answer the question
In order to leave comments, you need to log in
You seem to be using the get method inappropriately .
This is how it should work:
What kind of horror? You either type normally, or use whereLoose
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question