bradsi
11/20/2019 - 9:55 AM

Two Layers of Validation

Two Layers of Validation

Client Side Validation

i.e add required on the form

Server Side Validation

request()->validate([
  'title' => ['required', 'min:3'],
  'description' => 'required'
]);

If validation fails user will be redirected back to the previous page and validation errors are sent through.

Errors can be accessed through the errors variable.

@if ($errors->any())
  @foreach ($errors->all() as $error)
    <li>{{ $error }}</li>
  @endforeach
@endif

Retain Old Input

When validation fails, Laravel flashes the attributes to the session and we are fetching them value="{{ old('title') }}"

Docs

https://laravel.com/docs/6.x/validation