user()->can('edit', $this->invoice); } public function rules() { return [ 'action' => ['required'], ]; } public function withValidator($validator) { $validator->after(function ($validator) { if ($this->action == 'delete' && ! $this->invoiceDeletable($this->invoice)) { $validator->errors()->add('action', 'This invoice cannot be deleted'); }elseif ($this->action == 'cancel' && ! $this->invoiceCancellable($this->invoice)) { $validator->errors()->add('action', 'This invoice cannot be cancelled'); }elseif ($this->action == 'reverse' && ! $this->invoiceReversable($this->invoice)) { $validator->errors()->add('action', 'This invoice cannot be reversed'); }elseif($this->action == 'restore' && ! $this->invoiceRestorable($this->invoice)) { $validator->errors()->add('action', 'This invoice cannot be restored'); }elseif($this->action == 'mark_paid' && ! $this->invoicePayable($this->invoice)) { $validator->errors()->add('action', 'This invoice cannot be marked as paid'); } }); } public function prepareForValidation() { $input = $this->all(); $input['action'] = $this->route('action'); $this->replace($input); } }