Level 39
Apr 14, 2022
3
Level 2
Constant expression contains invalid operations
hello i am using laravel livewire and i want to validate a multi-step form so that the name matches the name of the logged in user but it's giving me the Constant expression contains invalid operations error
private $validationRules = [
1 => [
'name' => [
'required',
Rule::in(Auth::user()->name),
],
'phone' => 'required|min:3|integer',
'date' => 'required|date',
'file' => 'required|file|mimes:png,jpg,jpeg,pdf,doc,docx',
'lieu' => 'required',
'mother' => 'required',
],
2 => [
'name_father' => 'required|min:3',
'date_father' => 'required|date',
'lieu_father' => 'required',
'number_piece_father' => 'required',
'file_father' => 'required|file|mimes:png,jpg,jpeg,pdf,doc,docx',
'mother_father' => 'required',
],
];
Level 102
@ahmedmessi why not just add a rules() method that returns an array based on the current page?
public function rules()
{
$validationRules = [
1 => [
'name' => [
'required',
Rule::in(Auth::user()->name),
],
'phone' => 'required|min:3|integer',
'date' => 'required|date',
'file' => 'required|file|mimes:png,jpg,jpeg,pdf,doc,docx',
'lieu' => 'required',
'mother' => 'required',
],
2 => [
'name_father' => 'required|min:3',
'date_father' => 'required|date',
'lieu_father' => 'required',
'number_piece_father' => 'required',
'file_father' => 'required|file|mimes:png,jpg,jpeg,pdf,doc,docx',
'mother_father' => 'required',
],
];
return $validationRules[$this->currentPage];
}
Please or to participate in this conversation.