validated()); $resources = $action->index(ArtistImage::query(), $query, $request->schema()); return new ArtistImageCollection($resources, $query); } /** * Store a newly created resource. * * @param StoreRequest $request * @param Artist $artist * @param Image $image * @param StoreAction $action * @return ArtistImageResource */ public function store(StoreRequest $request, Artist $artist, Image $image, StoreAction $action): ArtistImageResource { $validated = array_merge( $request->validated(), [ ArtistImage::ATTRIBUTE_ARTIST => $artist->getKey(), ArtistImage::ATTRIBUTE_IMAGE => $image->getKey(), ] ); $artistImage = $action->store(ArtistImage::query(), $validated); return new ArtistImageResource($artistImage, new Query()); } /** * Display the specified resource. * * @param ShowRequest $request * @param Artist $artist * @param Image $image * @param ShowAction $action * @return ArtistImageResource */ public function show(ShowRequest $request, Artist $artist, Image $image, ShowAction $action): ArtistImageResource { $artistImage = ArtistImage::query() ->where(ArtistImage::ATTRIBUTE_ARTIST, $artist->getKey()) ->where(ArtistImage::ATTRIBUTE_IMAGE, $image->getKey()) ->firstOrFail(); $query = new Query($request->validated()); $show = $action->show($artistImage, $query, $request->schema()); return new ArtistImageResource($show, $query); } /** * Remove the specified resource. * * @param Artist $artist * @param Image $image * @param DestroyAction $action * @return JsonResponse */ public function destroy(Artist $artist, Image $image, DestroyAction $action): JsonResponse { $artistImage = ArtistImage::query() ->where(ArtistImage::ATTRIBUTE_ARTIST, $artist->getKey()) ->where(ArtistImage::ATTRIBUTE_IMAGE, $image->getKey()) ->firstOrFail(); $action->destroy($artistImage); return new JsonResponse([ 'message' => "Image '{$image->getName()}' has been detached from Artist '{$artist->getName()}'.", ]); } }