devnotes.

Validating Requests

Laravel provides several ways to validate incoming data. The simplest is directly inside a controller:

public function store(Request $request)
{
    $validated = $request->validate([
        'title' => 'required|string|max:255',
        'email' => 'required|email|unique:users,email',
        'age'   => 'nullable|integer|min:18',
        'body'  => 'required|string|min:10',
    ]);

    Post::create($validated);
    return redirect('/posts')->with('success', 'Post created!');
}

If validation fails, Laravel automatically redirects back with errors flashed to the session, and Blade's @error('field') directive displays them next to the relevant input, with old('field') re-populating the form so users don't lose their input.

Laravel ships dozens of built-in rules: required, email, unique, exists, confirmed, in:, date, image, mimes:jpg,png, regex:, and more, and you can chain custom closures or dedicated Rule objects for anything more specific — for example Rule::unique('users')->ignore($user->id) when updating a record.

Laravel Validation Rules Tutorial | DevNotes