Check all arrays except the last in laravel

With an asterisk, I can check all the elements of an array, for example:

'event_time_start.*' => 'required|date_format:G:i',

But I want to apply this validation rule to all elements except the last. How can i achieve this?

+4
source share
2 answers

It is recommended that you always exclude an unnecessary item from the front end. If not, you can delete the last item before sending the request data to Validator.

    $requestData = $request->all();
    $count = count($requestData["event_time_start"]);
    unset($requestData["event_time_start"][$count-1]);
    $validator = Validator::make( $requestData  , [
        'event_time_start.*' => 'required',
    ]);
0
source

JavaScript , . , name, . , name="event_time_start[]" .

, 6 .

0

Source: https://habr.com/ru/post/1692974/


All Articles