验证除laravel中的last以外的所有arrayitems [英] validate all arrayitems except last in laravel

查看:66
本文介绍了验证除laravel中的last以外的所有arrayitems的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用星号,我可以验证所有数组项,如下所示:

With the asterisk I can validate all array items, like this:

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

但是我想将此验证规则应用于除最后一项以外的所有项.我该如何实现?

But I want apply this validation rule on all items, except the last one. How can I achive this?

推荐答案

始终建议尽可能从前端排除不必要的项目.如果没有,您可以在将请求数据发送到Validator之前删除最后一项.

It is always recommended to exclude unnecessory item from front end if possible. If not you can remove last item before sending 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',
    ]);

这篇关于验证除laravel中的last以外的所有arrayitems的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆