4
0
Fork 0
master
panliang 2022-09-16 10:37:04 +08:00
parent aed7cf155f
commit 23c6bc2a53
1 changed files with 4 additions and 10 deletions

View File

@ -23,19 +23,13 @@ class BannerController extends Controller
},
])->enable()->whereIn('key', $keys)->get();
$mapAds = $ads->mapWithKeys(function ($item) use ($request) {
return [
$item->key => BannerResource::collection($item->banners)->resolve($request),
];
});
$data = [];
foreach ($keys as $key) {
if (! $mapAds->has($key)) {
$mapAds->put($key, []);
}
$ad = $ads->where('key', $key)->first();
$data[$key] = $ad ? BannerResource::collection($ad->banners) : [];
}
return $this->json($mapAds);
return $this->json($data);
}
}