current(); if ($customer === null || $current === null) { return null; } return DpaAcceptance::query() ->where('customer_id', $customer->id) ->where('dpa_version_id', $current->id) ->first(); } public function accepted(?Customer $customer): bool { return $this->acceptanceOf($customer) !== null; } /** * Record an acceptance. * * firstOrCreate over the pair the unique index covers: pressing twice is not * two agreements, and a double click must not become a duplicate-key error * in front of somebody agreeing to a contract. * * The address is read here rather than passed in, so no caller can record an * acceptance as coming from somewhere it invented. */ public function accept(Customer $customer, ?string $ip = null): ?DpaAcceptance { $current = $this->current(); if ($current === null) { return null; } return DpaAcceptance::query()->firstOrCreate( ['customer_id' => $customer->id, 'dpa_version_id' => $current->id], [ 'user_id' => Auth::id(), 'ip' => $ip ?? request()->ip(), 'accepted_at' => now(), ], ); } }