Forms

Repopulating Forms

When redirecting due to a validation error, request input is flashed to the session.
Retrieve the input from the previous request with the old method

$title = $request->old('title');

Or the old() helper

<input type="text" name="title" value="{{ old('title') }}">

Validation Errors

<!-- /resources/views/post/create.blade.php -->
<label for="title">Post Title</label>
<input id="title" type="text" class="@error('title') is-invalid @enderror">
@error('title')
    <div class="alert alert-danger">{{ $message }}</div>
@enderror

See: Validation

Method Field

Since HTML forms can't make PUT, PATCH, or DELETE requests, you will need to add a hidden _method field to spoof these HTTP verbs:

<form action="/post/my-post" method="POST">
    @method('PUT')
    ...
</form>

CSRF Field

Include a hidden CSRF token field to validate the request

<form method="POST" action="/profile">
    @csrf

    ...
</form>

See: CSRF Protection

Comments