Jul 2, 2022
0
Level 36
Validation with laravel nova custom tool
I have some form in custom laravel nova tool and I am not sure how can I handle and show validation error messages.
In Tool.vue I have a method for handling form which is look something like this:
createInvoice() {
Nova.request().post('/nova-vendor/invoice-creation', this.form)
...
},
In api.php I have basic thing:
Route::post('/', \App\Http\Controllers\CreateInvoiceController::class);
and my controller looks like this:
class CreateInvoiceController extends Controller
{
public function __invoke(StoreInvoice $request)
{
$data = $request->validated();
$invoiceData = Arr::except($data, 'items');
$servicesData = collect(Arr::only($data, 'items'))->flatten(1)->toArray();
/** @var Invoice $invoice */
$invoice = Invoice::create($invoiceData);
$invoice->services()->createMany($servicesData);
}
}
What should I return from controller and how to pass validation errors and handle that on client side?
Please or to participate in this conversation.