← Back to Course

Validating Input Data

Accepting user input is only safe once it has been checked against clear rules. Laravel's validation system makes this straightforward, offering a large set of built-in rules along with automatic error handling for the browser-facing side of an application.

Validating Inside a Controller

The most common approach is calling the request's validate() method directly inside a controller, passing an array of field names mapped to validation rules. If validation fails, Laravel automatically redirects back to the previous page with the errors and old input flashed to the session.

Common Validation Rules

RuleWhat It Checks
requiredThe field must be present and not empty
emailThe value must be a properly formatted email address
min:8 / max:255Enforces a minimum or maximum length
unique:users,emailThe value must not already exist in a given table/column
confirmedRequires a matching *_confirmation field, common for passwords

Displaying Errors in a View

Built-in rules cover most situations, but applications often need checks that are specific to their own business logic — which is where custom validation rules and messages come in.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course