user(); return $user->isAdmin(); } public function prepareForValidation() { $input = $this->all(); if (! isset($input['gateway_refund'])) { $input['gateway_refund'] = false; } if (! isset($input['send_email'])) { $input['send_email'] = false; } if (isset($input['id'])) { $input['id'] = $this->decodePrimaryKey($input['id']); } if (isset($input['invoices'])) { foreach ($input['invoices'] as $key => $invoice) { $input['invoices'][$key]['invoice_id'] = $this->decodePrimaryKey($invoice['invoice_id']); } } if (isset($input['credits'])) { unset($input['credits']); } $this->replace($input); } public function rules(): array { $input = $this->all(); $rules = [ 'id' => 'bail|required', //@phpstan-ignore-line 'id' => new ValidRefundableRequest($input), 'amount' => 'numeric', 'date' => 'required', 'invoices.*.invoice_id' => 'required', 'invoices.*.amount' => 'required', 'invoices' => new ValidRefundableInvoices($input), ]; return $rules; } public function payment(): ?\App\Models\Payment { $input = $this->all(); return Payment::whereId($input['id'])->first(); } }