check()) { return false; } /** @var \App\Models\User */ $user = auth()->user(); return $user->isAdmin() and $user->can('estimate', $this->ticket); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { /** @var \App\Models\Ticket */ $ticket = $this->ticket; return [ 'amount' => [ 'required', 'numeric', 'gt:0', function ($attribute, $value, $fail) { if (fmod((\floatval($value) * 1000), 62.5) !== 0.0) { $fail("$attribute doit être un multiple de 62.5 (soit 0.0625)"); } } ], 'credit_account_id' => [ 'required', 'exists:credit_accounts,id', function ($attribute, $value, $fail) use ($ticket) { /** @var \App\Models\Credit\Account|null */ $account = Account::whereId($value)->first(); if ($account and !$ticket->accountIsValidForThisTicket($account)) { $fail("$attribute does not belong to the ticket brand"); } } ] ]; } /** * Get custom messages for validator errors. * * @return array */ public function attributes(): array { return [ 'amount' => 'Montant', 'credit_account_id' => 'Compte à débiter' ]; } }