1. Home
  2. Laravel
  3. Validate
#laravel#controller#data

Validate function allows you to set rules for the data passed in the request. If the validation fails Laravel returns an Errors object.

// Controller file
public function store() {
    request()->validate([
        'FirstName' => 'required',
        'SecondName' => 'required'
    ]);
}

// View file
@if ($errors->any())
    @foreach ($errors->all() as $error)
        {{ $error }}
    @endforeach
@endif
copy
Full Laravel cheatsheet
Sitemap Git repository