cms icon indicating copy to clipboard operation
cms copied to clipboard

[4.x] Support Laravel precognition on user forms

Open ryanmitchell opened this issue 9 months ago • 1 comments

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

ryanmitchell avatar Nov 03 '23 16:11 ryanmitchell

@jasonvarga I've updated this now the main PR has merged. It should follow the same principles.

ryanmitchell avatar Dec 01 '23 06:12 ryanmitchell

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 }}),
}'>

jasonvarga avatar May 15 '24 20:05 jasonvarga

Thank you ❤️

ryanmitchell avatar May 16 '24 12:05 ryanmitchell