Type error: Argument 1 passed to App\Http\Controllers\Auth\RegisterController::register() must be of the type array, object given

Published 4 months ago by irankhosravi

What is this error?

Type error: Argument 1 passed to App\Http\Controllers\Auth\RegisterController::register() must be of the type array, object given

public function register(array $data, Request $request)
    {
        if ($request->hasFile('image')) {
            $fileNameWithExt = $request->file('image')->getClientOriginalName();
            $filename = pathinfo($fileNameWithExt, PATHINFO_FILENAME);
            $extention = $request->file('image')->getClientOriginalExtension();
            $fileNameToStore = $filename.'_'.time().'.'.$extention;
            $path = $request->file('image')->storeAs('public/images', $fileNameToStore);
        } else {
            $fileNameToStore = 'noimage.jpg';
        }

        return User::create([
            'firstname' => $data['firstـname'],
            'lastname' => $data['lastـname'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'mobile' => $data['mobile'],
            'nasional_code' => $data['national_code'],
            'birthdate' => $data['birthـdate'],
            'document' => $data['document'],
            'educational' => $data['educational'],
            'gender' => $data['gender'],
            'side' => $data['side'],
            $fileNameToStore => $data['image']
        ]);
    }
Dry7
Dry7
4 months ago (152,030 XP)

@irankhosravi how do you call this method?

Cronix
Cronix
4 months ago (786,650 XP)
register(array $data, Request $request)

This is saying that the first parameter, $data, must be an array.

However, when you use this, you're not passing an array. You're passing an object as the first parameter to that function/method.

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