Chron
3 months ago
38
19
Laravel

How to pass multiple variables in withErrors?

Posted 3 months ago by Chron

Here's the validation:

$infoValidated = Validator::make($request->only([
        'firstname','middlename','lastname',
    ]),
     [
        'firstname' => 'required|string|min:2',
        'middlename' => 'nullable',
        'lastname' => 'required|string|min:2',
    //and other fields
    ]);

$infoValidated = Validator::make($request->only([
        'email'
    ]),
     [
    'email' => 'required|email',
    //and other fields
    ]);

if ($accountValidated->fails() || $infoValidated->fails()) {
         return redirect()->route('customer.create')
         ->withErrors($accountValidated)
         ->withInput();
     }

I would like to pass the $accountValidated and $infoValidated, how can I do it? I tried using but I got Cannot use object of type Illuminate\Validation\Validator as array

Please sign in or create an account to participate in this conversation.