json($customer->addresses); } /** * Store a newly created resource in storage. */ public function store(Request $request, Customer $customer): JsonResponse { $addressData = $request->validate([ 'name' => 'required|string', 'email' => 'required|string|email', 'phone' => 'string', 'address' => 'string', 'city' => 'string', 'zip' => 'numeric', 'is_address' => 'boolean', 'is_delivery' => 'boolean', ]); if (isset($addressData['is_address']) && $addressData['is_address'] == 1) { $customer->addresses()->where('is_address', true)->update(['is_address' => false]); } if (isset($addressData['is_delivery']) && $addressData['is_delivery'] == 1) { $customer->addresses()->where('is_delivery', true)->update(['is_delivery' => false]); } $address = $customer->addresses()->create($addressData); return response()->json($address); } /** * Display the specified resource. */ public function show(Address $address): JsonResponse { return response()->json($address); } /** * Update the specified resource in storage. */ public function update(Request $request, Address $address): JsonResponse { $customer = $address->customer; $addressData = $request->validate([ 'is_address' => 'boolean', 'is_delivery' => 'boolean', ]); if (isset($addressData['is_address']) && $addressData['is_address'] == 1) { $customer->addresses()->where('is_address', true)->update(['is_address' => false]); } if (isset($addressData['is_delivery']) && $addressData['is_delivery'] == 1) { $customer->addresses()->where('is_delivery', true)->update(['is_delivery' => false]); } $address->update($addressData); return response()->json($address); } /** * Remove the specified resource from storage. */ public function destroy(Address $address): JsonResponse { $address->delete(); return response()->json(null, 204); } }