I'm trying to validate some data with laravel, which I have implemented in the Model itself, as such:
class Collection extends Model { protected $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 ]);
However, upon submitting data, and supposedly having it go through this validation, it gives me the error seen in the title:
Constant expression contains invalid operations in {link to model}:39
I've numbered the lines of code too and I'm not sure why this specifically is happening.
Thanks in advance for any guidance.
!=
java. it just won't compiled, ...yet. you can't create nesting array like that on class property. Instead, set them on constructor. – Chay22implode(',', $allowedDataTypes)
is triggering the error – Sandeesh