Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ahmedmessi's avatar

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',
        ],
];
0 likes
3 replies
ahmedmessi's avatar

@sr57 yes but except that I can't use the rules method because I'm working on a multi-step form and the data is valid before going to the next step. To validate the data before going to the next step I do

public function goToNextPage()
{
    $this->validate($this->validationRules[$this->currentPage]);
    $this->currentPage++;
}
Sinnbeck's avatar
Sinnbeck
Best Answer
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.