photos()->orderBy('created_at', 'desc')->get(); return PhotoResource::collection($photos); } /** * Store the Photo. * * @param Request $request * @param Contact $contact * * @return PhotoResource */ public function store(Request $request, Contact $contact): PhotoResource { $photo = app(UploadPhoto::class)->execute([ 'account_id' => auth()->user()->account->id, 'photo' => $request->photo, ]); $contact->photos()->syncWithoutDetaching([$photo->id]); return new PhotoResource($photo); } /** * Delete the Photo. * Also, if this photo was the current avatar of the contact, change the * avatar to the default one. * * @param Request $request * @param Contact $contact * @param Photo $photo * * @return null|\Illuminate\Http\JsonResponse */ public function destroy(Request $request, Contact $contact, Photo $photo) { $data = [ 'account_id' => auth()->user()->account->id, 'photo_id' => $photo->id, ]; try { app(DestroyPhoto::class)->execute($data); } catch (\Exception $e) { return $this->respondNotFound(); } } }