brand, $request->email)->exists()) { throw new ApiErrorException(ApiError::singleOptinCustomerExists()); } /** @var \App\Models\SingleOptin */ $singleOptin = SingleOptin::where('email', $request->email)->firstOrNew(); if ($request->opt_in) { $singleOptin->fill($request->validated()); $singleOptin->brand()->associate($service->brand); $singleOptin->saveOrFail(); } else { $singleOptin->delete(); } return response()->json(); } }