0

I have overwritten the default user table with an existing table. When trying to register a new user i get the following error:

Argument 1 passed to Illuminate\Auth\SessionGuard::login() must be an instance of Illuminate\Contracts\Auth\Authenticatable, instance of App\customUser given, called in {path}\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php on line 35

To overwrite the default users table with my own I have made the following changes:

///Auth.php///

//Auth defaults:
'defaults' => [
        'guard' => 'web',
        'passwords' => 'customusers',
    ],

//Auth guards:
'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'customusers',
        ],

//User providers:
'providers' => [
        'customusers' => [
            'driver' => 'eloquent',
            'model' => App\customUser::class,
        ],

I don't know if these changes could cause the error I'm facing.

The error is supposedly fired in this part of 'RegisterUsers.php'

$this->guard()->login($user);

This is part of the function 'register', which looks like this:

public function register(Request $request)
    {
        $this->validator($request->all())->validate();

        event(new Registered($user = $this->create($request->all())));

        $this->guard()->login($user);

        return $this->registered($request, $user)
                        ?: redirect($this->redirectPath());
    }

Any help regarding this error would be kindly appreciated, I'm fairly new to Laravel so I would like to recieve a clear explanation to my problem so I can understand why it is calling this error.

Kind regards, geertjanknapen

2 Answers 2

0

Your model needs to extend Illuminate\Foundation\Auth\User, otherwise you cannot use it with the authentication methods like login / logout etc.

In your customUser model add the following:

use Illuminate\Foundation\Auth\User as Authenticatable;

class customUser extends Authenticatable

I would also recommend to rename your class customUser to CustomUser in order to follow PSR-1:

Class names MUST be declared in StudlyCaps.

The term ‘StudlyCaps’ in PSR-1 MUST be interpreted as PascalCase where the first letter of each word is capitalized including the very first letter.

Sign up to request clarification or add additional context in comments.

Comments

0

On RegisterUsers.php you need to include

use Illuminate\Foundation\Auth\AuthenticatesUsers;

and below class RegisterUsers extends Controller

you need to add

use AuthenticatesUsers;

2 Comments

I think this is wrong. Is it that CustomUser needs to extend Illuminate\Foundation\Auth\User?
maybe that's the one! One or the other anyway

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.