在我的应用程序中,我尝试使用required_unless验证程序,但是每次我击中控制器时都会引发错误;
Method Illuminate\Validation\Validator::validateRequiredUnless,meta.app,pos does not exist.
这是跟踪:
Message
Method Illuminate\Validation\Validator::validateRequiredUnless,meta.app,pos does not exist.
Level
ERROR
Exception
```{
"class": "BadMethodCallException",
"message": "Method Illuminate\\Validation\\Validator::validateRequiredUnless,meta.app,pos does not exist.",
"code": 0,
"file": "\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Validation\/Validator.php:1146",
"trace": [
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Validation\/Validator.php:365",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Validation\/Validator.php:268",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Validation\/Validator.php:293",
"\/var\/app\/current\/app\/Http\/Controllers\/Shared\/CheckoutController.php:76",
"{\"function\":\"checkout\",\"class\":\"App\\\\Http\\\\Controllers\\\\Shared\\\\CheckoutController\",\"type\":\"->\",\"args\":[\"[object] (Illuminate\\\\Http\\\\Request)\"]}",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Controller.php:54",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/ControllerDispatcher.php:45",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Route.php:212",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Route.php:169",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Router.php:665",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Pipeline.php:30",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Middleware\/SubstituteBindings.php:41",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Pipeline\/Pipeline.php:151",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Pipeline.php:53",
"\/var\/app\/current\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/Middleware\/ThrottleRequests.php:57",
"\/va…
这是我的验证码:
$rules = [
"client" => "required_unless,meta.app,pos",
"customer" => "required",
"customer.fullname" => "required|min:4",
"customer.phone" => "required|numeric",
"customer.email" => "email|required_unless,meta.app,pos",
"payment" => "required",
"payment.type" => "required",
"items" => "required",
"items.*.id" => "required",
"items.*.quantity" => "required_if:meta.type,==,event|numeric",
"items.*.seat" => "required_if:meta.type,==,food",
"meta" => "required",
"meta.type" => "required",
"meta.timestamp" => "required",
"meta.token" => "required_unless,meta.app,pos"
];
$validator = Validator::make($request->all(), $rules, []);
// Validate incoming request
if ($validator->fails()) {
return response($validator->errors(), 400);
}
答案 0 :(得分:2)
在:
之后,应该是,
而不是required_unless
。
required_unless:anotherfield,value,
尝试required_unless:meta.app,pos