source) ->where('source_id', $address->source_id) ->where('id', '!=', $id) ->update(['is_primary' => false]); } $address->fill($data); $address->save(); return $address->fresh(); } public function delete(int $id): bool { $address = Address::findOrFail($id); return $address->delete(); } // public function findBySource(array $data): ?Collection { $allAddresses = Address::where('source', data_get($data, 'source')) ->where('source_id', data_get($data, 'source_id')) ->with(['city', 'state']) ->whereNull('deleted_at') ->orderBy('is_primary', 'desc') ->get(); return $allAddresses; } public function findPrimaryBySource(array $data): ?Address { return Address::where('source', data_get($data, 'source')) ->where('source_id', data_get($data, 'source_id')) ->whereNull('deleted_at') ->orderBy('is_primary', 'desc') ->first(); } }