cms
cms copied to clipboard
[4.x] Support Laravel precognition on user forms
This PR adds support for Laravel Precognition to user forms (login, register, profile and password).
Again I've moved the validation logic out of the UserController and into separate FormRequests.
Closes #6950 Closes #7890
@jasonvarga I've updated this now the main PR has merged. It should follow the same principles.
Just putting these here for the docs. When following our own forms docs for how to set up precognition, it explains we have to add an inner div with the precognition $form. Since the user tags don't have the whole js driver x-data thing, we can't grab the data off the <form> tag.
Instead, we can grab the values from fields.
{{? $values = collect($fields)->mapWithKeys(fn ($field) => [
$field['handle'] => $field['value']
]) ?}}
<div x-data='{
form: $form(
"post",
$refs.form.getAttribute("action"),
{{$ $values->toJson() $}}
).setErrors({{ error | json }}),
}'>
Thank you ❤️