user()->can('create', Payment::class); } public function rules() { $this->sanitize(); $rules = [ 'amount' => 'numeric|required', 'payment_date' => 'required', 'client_id' => 'required', 'invoices' => 'required', 'invoices' => new ValidPayableInvoicesRule(), ]; return $rules; } public function sanitize() { $input = $this->all(); if(isset($input['client_id'])) $input['client_id'] = $this->decodePrimaryKey($input['client_id']); if(isset($input['invoices'])) $input['invoices'] = $this->transformKeys(explode(",", $input['invoices'])); if(is_array($input['invoices']) === false) $input['invoices'] = null; $this->replace($input); return $this->all(); } }