Answer the question
In order to leave comments, you need to log in
Laravel how to add 2 collections to one collection?
Hello.
How to add one collection to another?
$categories - a collection of all categories
$alias - an array of urls by which we are looking for categories
$array - all collections of categories should be saved here, but not in an array, otherwise it is difficult / inconvenient to get it later.
function searchCategoryAlias($categories, $alias, $array = null){
foreach ($alias as $k => $v){
$category = $categories->where('alias', $v);
$array = collect($category);
}
return $array;
}
Answer the question
In order to leave comments, you need to log in
here even I sweated) $category returns an array that needs to be passed through foreach and added to $array in it
You need to start by reading the documentation https://laravel.com/docs/8.x/collections
If then something is not clear, ask, showing what did not work out.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question