1. Home
  2. Laravel
  3. Validate

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

#laravel#controller#data
// 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