I got a few parameters in the url that I want to loop into a Laravel where query. After doing that I want to merge them into 1 collection and without duplicates.
This is what I have written already:
foreach($request->query() as $key => $query){
$guides[] = SupportGuideTranslation::where($key, $query)->get();
}
These are my parameters:
?active=1&language_id=2
My Answer:
>all() as $key => $value) {
$query = Model::where($key, $value);
$queries[] = $query;
}
$mergedCollection = collect();
foreach ($queries as $query) {
$results = $query->get();
$mergedCollection = $mergedCollection->merge($results);
}
$uniqueMergedCollection = $mergedCollection->unique();
return $uniqueMergedCollection;
Rate this post
4 of 5 based on 9689 votesComments