A Comprehensive Guide to Laravel Validation

ArjunAmrutiya
3 min readSep 3, 2023

Introduction
Validation is a crucial aspect of web application development, ensuring that the data your application receives is accurate and secure. Laravel, a popular PHP framework, provides a robust and flexible validation system that makes it easy to validate user input. In this blog post, we will explore Laravel validation step by step, covering various validation methods with example code.

1. Basic Validation

Required Fields:
You can use the required validation rule to ensure that a field is not empty:

use Illuminate\Support\Facades\Validator;

$validator = Validator::make($request->all(), [
'name' => 'required',
]);

String Length:
You can specify the minimum and maximum length of a string using min and max rules:

$validator = Validator::make($request->all(), [
'username' => 'min:3|max:20',
]);

Numeric Values:
To validate numeric input, use the numeric rule:

$validator = Validator::make($request->all(), [
'age' => 'numeric',
]);

2. Common Validation Rules

--

--

ArjunAmrutiya
ArjunAmrutiya

Written by ArjunAmrutiya

👋 Hey there! I'm Arjun Amrutiya, a passionate web developer and blogger who loves all things PHP, Laravel and Vue.js. Welcome to my Medium account!

No responses yet