【发布时间】:2017-10-19 09:18:30
【问题描述】:
我正在尝试使用 laravel 验证一些数据,我已经在模型本身中实现了这些数据,例如:
类集合扩展模型 { 受保护的 $guarded = [ 'id' ];
public $allowedDataTypes = [
'Date',
'Text',
'Number',
'Email',
'Checkbox',
'Image',
'File',
];
25 public static $rules = array([
26
27 'fields.*.fieldName' =>
28 [
29 'unique' => 'Please ensure that the fields are uniquely named.',
30 'required' => 'You must specify a name for your fields.'
31 ],
32
33 'fields.*.dataType' =>
34 [
35 'required', 'You must specify a data type for your fields.',
36 'in:'.implode(',', $allowedDataTypes)
37 ]
38
39 ]);
但是,在提交数据并假设它通过此验证时,它给了我标题中看到的错误:
常量表达式在 {link to 型号}:39
我也对代码行进行了编号,但我不确定为什么会发生这种情况。
提前感谢您的任何指导。
【问题讨论】:
-
dd($allowedDataTypes); 做什么输出? (在函数开始时执行)
-
它甚至不会让我走那么远。我将在问题中添加它的声明
-
php
!=java。它只是不会编译,......还没有。你不能在类属性上创建像这样的嵌套数组。相反,将它们设置在构造函数上。 -
您不能在声明中使用表达式。
implode(',', $allowedDataTypes)正在触发错误
标签: php laravel validation