John Davidson

php - Loop parameters through a query collection and then merge them (Laravel 8)

0 comments
Message:


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

3 of 5 based on 8712 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us