How to validate array in Laravel

0 votes

I try to validate array POST in Laravel:

$validator = Validator::make($request->all(), [
            "name.*" => 'required|distinct|min:3',
            "amount.*" => 'required|integer|min:1',
            "description.*" => "required|string"

        ]);

I send empty POST and get this if ($validator->fails()) {} as False. It means that validation is true, but it is not.

How to validate array in Laravel? When I submit form with input name="name[]"

Aug 10, 2020 in Laravel by kartik
• 37,520 points
31,259 views

1 answer to this question.

0 votes

Hello @kartik,

you can call validate() method directly on Request object like so:

$data = $request->validate([
    "name"    => "required|array|min:3",
    "name.*"  => "required|string|distinct|min:3",
]);

Hope it helps!!
Thank You!!

answered Aug 10, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer

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

Hello @kartik, try using nullable as a rule 'password' ...READ MORE

answered Sep 25, 2020 in Laravel by Niroj
• 82,840 points
15,947 views
0 votes
1 answer

How to validate exact words in Laravel?

Hello, Try this code: // option one: 'in' takes ...READ MORE

answered Dec 4, 2020 in Laravel by Niroj
• 82,840 points
2,650 views
0 votes
1 answer

How to pass URL param in Laravel?

Hello, First you have to go to routes ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
5,189 views
0 votes
1 answer

How to pass data through URL and access through controller in Laravel?

Hello, You can  first refer how to  Create controller through ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
11,902 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,012 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
2,994 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,918 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
44,691 views
0 votes
1 answer

Explain validations in laravel and How to validate my application incoming data?

Hey @kartik, In Programming validations are a handy ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
1,432 views
0 votes
1 answer

How to validate Route Parameters in Laravel?

Hello @kartik, The issue is route parameters aren't ...READ MORE

answered Sep 25, 2020 in Laravel by Niroj
• 82,840 points
11,482 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP