Tutorial by Examples

You can validate request data using the validate method (available in the base Controller, provided by the ValidatesRequests trait). If the rules pass, your code will keep executing normally; however, if validation fails, an error response containing the validation errors will automatically be se...
Validating array form input fields is very simple. Suppose you have to validate each name, email and father name in a given array. You could do the following: $validator = \Validator::make($request->all(), [ 'name.*' => 'required', 'email.*' => 'email|unique:users'...
1) Form Request Validation You may create a "form request" which can hold the authorization logic, validation rules, and error messages for a particular request in your application. The make:request Artisan CLI command generates the class and places it in the app/Http/Requests director...
Following the 'Form Request Validation' example, the same Request Class can be used for POST, PUT, PATCH so you do not have to create another class using the same/similar validations. This comes in handy if you have attributes in your table that are unique. /** * Get the validation rules that a...
Customizing error messages The /resources/lang/[lang]/validation.php files contain the error messages to be used by the validator. You can edit them as needed. Most of them have placeholders which will be automatically replaced when generating the error message. For example, in 'required' => '...
If you want to create a custom validation rule, you can do so for instance in the boot method of a service provider, via the Validator facade. <?php namespace App\Providers; use Illuminate\Support\ServiceProvider; use Validator; class AppServiceProvider extends ServiceProvider { ...

Page 1 of 1