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(); ])->enable()->whereIn('key', $keys)->get();
$mapAds = $ads->mapWithKeys(function ($item) use ($request) { $data = [];
return [
$item->key => BannerResource::collection($item->banners)->resolve($request),
];
});
foreach ($keys as $key) { foreach ($keys as $key) {
if (! $mapAds->has($key)) { $ad = $ads->where('key', $key)->first();
$mapAds->put($key, []); $data[$key] = $ad ? BannerResource::collection($ad->banners) : [];
}
} }
return $this->json($mapAds); return $this->json($data);
} }
} }