Wednesday, January 31, 2018

laravel call to undefined method Auth guard - development

laravel call to undefined method Auth guard

i want to prevent the login after register in Laravel 5.5, I already did this by commenting a line:

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());
    }

i override it in RegisterController.php

i got this error:

Call to undefined method IlluminateAuthAuthenticationException::guard()
    $guard = array_get($exception->guard(),0);
    switch ($guard) {
        case 'admin':
            return redirect()->guest(route('admin.login'));
            break;

        default:
            return redirect()->guest(route('login'));
            break;
    }

Here is the content of my config/auth:

<?php

return [



    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],



    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'admin' => [
            'driver' => 'session',
            'provider' => 'admins',
        ],
        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],



    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => AppUser::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => AppAdmin::class,
        ],


    ],



    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        'admins' => [
            'provider' => 'admins',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

i have enabled multi-auth system which is i have an admin login and a user login, what i wan’t is to disable the login after register in my user page.



from Laravel Questions and Answers https://laravelquestions.com/laravel/laravel-call-to-undefined-method-auth-guard/
via Lzo Media

No comments:

Post a Comment