laravel验证规则max:value不适用于变量 [英] laravel validation rule max:value not working with variables

查看:437
本文介绍了laravel验证规则max:value不适用于变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是laravel的newby,我正在尝试使用max:value规则从我的输入请求中验证某个字段,事实是该值既不是静态值也不是我的请求输入中的字段,它是我从数据库中检索并存储在变量$ available中的值,每当我尝试使用('count'=> required | numeric | max:$ available)时,验证总是在max上失败,就好像无法评估该变量$ available但是,当我尝试使用不是这种情况的静态值(例如'count'=> required | numeric | max:5)时,它就可以正常工作,我也尝试在之前将$ available与请求的输入字段合并使用"$ request-> merge([''availableCount'=> $ availableRoom-> count])进行验证; ",然后我尝试在规则中使用字段"availableCount"而不是变量(例如"count" => required | numeric | max:availableCount),验证就永远不会失败,并且总是通过控制器逻辑进行!我做错了什么或我应该怎么做?谢谢.

i’m a newby in laravel , i’m trying to validate a certain field from my input request using the max:value rule , the thing is that the value is neither a static value nor a field in my request input , its a value that i retrieve from my database and stored in a variable $available , whenever i try ( ‘count’ => required|numeric|max:$available ) the validation always fails on max as if it cannot evaluate that variable $available , however when i try to use a static value which is not the case (e.g ‘count’ => required|numeric|max:5 ) it works just fine , i also tried to merge $available with the input fields of my request before validation using " $request->merge(['availableCount' =>$availableRoom->count]); " and then i tried to use the field ‘availableCount’ in my rule instead of the variable (e.g ‘count’ => required|numeric|max:availableCount) the validation never fails and it always proceeds with the controller logic !! what did i do wrong or what am i supposed to do ?! Thanks.

推荐答案

如果此更新不起作用,则进行一次小更新.

A small update if this doesn't work.

尝试:

'count' => 'required|numeric|max:{$available}'

这篇关于laravel验证规则max:value不适用于变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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