1

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 Illuminate\Auth\AuthenticationException::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' => App\User::class,
        ],
        'admins' => [
            'driver' => 'eloquent',
            'model' => App\Admin::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.

3
  • post the contents of your config/auth.php Commented Jan 31, 2018 at 7:24
  • @SapneshNaik hello sir i posted my config/auth please help thanks Commented Jan 31, 2018 at 7:27
  • @SapneshNaik why is it error? Commented Jan 31, 2018 at 7:39

1 Answer 1

2

To check guard in the exception can do something like this:

return redirect(route(auth()->guard('admin')->check() ? 'admin.login' : 'login'));

Also, use auth() helper or Auth:: facade in the RegisterController@register if you're trying to override the method:

auth()->guard('admin')->login($user);
Sign up to request clarification or add additional context in comments.

4 Comments

hi @Alexey because i make it multi-auth system with admin. Where would i change this?. please help thanks
still error, i put the first line in unauthenticated and override the auth()->guard('admin')->login($user); in registerController
@JcJohn and what about exception? Have you tried the code for exception?
@JcJohn you're using this code in an exception? Have you tried to use the code from my answer (the first part of it)?

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.