0

I have pass an arraybooking_type_all parameter in custom validation.
It's giving the error:

Array to string conversion

How to pass the array?

$validatedData = Validator::make($request->all(),[
        'couponcode' => 'validcoupon:$request->booking_type_all,
    ]);

Array booking_type_all:

array:1 [
  "TOURS" => array:1 [
    0 => "99848892-8617-41b9-808c-c44ca529d4e1"
  ],
  "VEHICLE" => array:1 [
    0 => "99848892-8617-41b9-808c-c44ca529d4e2"
  ]
]

1 Answer 1

0

I am not sure you are understanding the concept of "Custom Validation" here. I would suggest you go through the documentation here to understand it thoroughly.

In short, when you create a custom validation rule, preferably "Using Rule Objects", your rule will start working exactly the same as inbuild validation rules required, nullable, etc. work.

So you provide the whole request for validation and as a key, the name of variable you want to validate and as value, the rules you want to validate on that variable.

You do not need to provide particular array for particular custom validation.

So you will do something like this:

$validatedData = Validator::make($request->all(),[
    'booking_type_all' => 'validcoupon',
]);

where validcoupon is a custom rule to validate the array booking_type_all which is present in request payload.

Or

If you want to validate the keys present inside booking_type_all array only and it contains some key like couponcode for which you have created your custom validation then you can do it like this:

$validatedData = Validator::make($request->booking_type_all,[
    'couponcode' => 'validcoupon',
]);

In this scenario, you dont care about full request payload as you are only concerned with booking_type_all array in it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.