Questions tagged [laravel-validation]

This tag references different approaches to validate your application's incoming data using Laravel.

Laravel provides several different approaches to validate your application's incoming data. By default, Laravel's base controller class uses a ValidatesRequests trait which provides a convenient method to validate incoming HTTP request with a variety of powerful validation rules.

Read More

852 questions
79
votes
13 answers

Custom Laravel validation messages

I'm trying to create customized messages for validation in Laravel 5. Here is what I have tried so far: $messages = [ 'required' => 'Harap bagian :attribute di isi.', 'unique' => ':attribute sudah digunakan', ]; $validator =…
YVS1102
  • 2,658
  • 5
  • 34
  • 63
70
votes
9 answers

Undefined variable: errors in Laravel

When I want to register a user in my laravel project, the page always says Undefined variable: errors (View: /var/www/resources/views/auth/register.blade.php)" According to the Laravel documentation, $errors should always automatically be…
Anhinga
  • 823
  • 2
  • 7
  • 9
63
votes
3 answers

validating a numeric input's length in laravel 5

foo.blade.php FooController.php $rules = [ 'national-id' => 'required|size:10|numeric' ]; the national-id field should contain 10 digits and I actually expected the code above to validate this , but…
bobD
  • 1,037
  • 2
  • 9
  • 17
63
votes
23 answers

Laravel check for unique rule without itself in update

I am having my validation rules for unique in the update section. In inserting or adding the unique rule is 'Email' => array('unique:driver_details'), and it will check for the unique coloumn. But this fails for the update section. While updating…
user3388086
53
votes
6 answers

How to validate time in laravel

I want to validate time in Laravel. Ex:- I want that when user input the time between 8 PM to 10 PM then it will show the validation error. How can I achieve that in Laravel
Vikash
  • 3,391
  • 2
  • 23
  • 39
51
votes
9 answers

How add Custom Validation Rules when using Form Request Validation in Laravel 5

I am using form request validation method for validating request in laravel 5.I would like to add my own validation rule with form request validation method.My request class is given below.I want to add custom validation numeric_array with field…
gsk
  • 2,329
  • 8
  • 32
  • 56
50
votes
8 answers

Laravel validation: exists with additional column condition - custom validation rule

Is there is a way of referencing another field when specifying the exists validation rule in Laravel? I want to be able to say that input a must exist in table a, input b must exist in table b AND the value for column x in table b must equal input…
Jonathon
  • 15,873
  • 11
  • 73
  • 92
49
votes
2 answers

Laravel 5.3 Validation Fails when Variables are Null

Since upgrading laravel from 5.1 to 5.3, I've got couple of odd issues with Validation. When I post a data like this: firstName null And the validation rules are like this: $validator = Validator::make($postData, [ 'firstName' …
Neel
  • 9,352
  • 23
  • 87
  • 128
47
votes
8 answers

How to use the request route parameter in Laravel 5 form request?

I am new to Laravel 5 and I am trying to use the new Form Request to validate all forms in my application. Now I am stuck at a point where I need to DELETE a resource and I created a DeleteResourceRequest for just to use the authorize method. The…
Rohan
  • 13,308
  • 21
  • 81
  • 154
42
votes
10 answers

Laravel 5 how to validate route parameters?

I want to validate the route parameters in the "form request" but don't know how to do it. Below is the code sample, I am trying with: Route // controller Server Route::group(['prefix' => 'server'], function(){ …
40
votes
5 answers

How to return custom error message from controller method validation

How to return a custom error message using this format? $this->validate($request, [ 'thing' => 'required' ]);
cmac
  • 3,123
  • 6
  • 36
  • 49
32
votes
6 answers

How to force FormRequest return json in Laravel 5.1?

I'm using FormRequest to validate from which is sent in an API call from my smartphone app. So, I want FormRequest alway return json when validation fail. I saw the following source code of Laravel framework, the default behaviour of FormRequest is…
Chung
  • 947
  • 1
  • 12
  • 22
27
votes
5 answers

Laravel: Validating a number greater than zero is failing

I gotta validate a price field which needs to be greater than zero (0.01 is valid) so I have the following validation: $request->validate([ 'product_price' => 'required|numeric|gt:0', ]); The problem is that when I enter a…
MrCujo
  • 1,218
  • 3
  • 31
  • 56
27
votes
5 answers

Laravel validation rules - optional, but validated if present

I'm trying to create a user update validation through form, where I pass, for example 'password'=>NULL, or 'password'=>'newone'; I'm trying to make it validate ONLY if it's passed as not null, and nothing, not even 'sometimes' works :/ I'm trying to…
GTMeteor
  • 807
  • 3
  • 9
  • 17
24
votes
4 answers

How to validate an input field if value is not null in Laravel

I am trying to create and update users with laravel 5.4 This is the validation added for create user. It works. $this->validate($request, [ 'name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' =>…
noufalcep
  • 3,446
  • 15
  • 33
  • 51
1
2 3
56 57