Skip to main content

Inertia Forms

lact also handles submitting a form using Inertia.js forms.

Consideration

Backend

class SomeController extends Controller
{
#[Action(method: 'post')]
public function functionName()
{
return [];
}
}

Frontend

import { functionName } from '@actions/SomeController.js';

Usage

let form = useForm({
name: 'name',
email: 'email'
})

form.submit(functionName.form(), {
onSuccess: (res) => {
console.log(res)
},
});

.form() Is a method which returns the method and url. You can also pass params to form() to pass the params to url.

functionName.form({
user: 1
})

/*
* {method: 'post', url: '.../1'}
* */