Ad

Cannot Redirect To A Path In Laravel 5.2

- 1 answer

In laravel 5.1 I have overwrite postRegister then redirect it to a path and it worked well, but in Laravel 5.2 I write the same code it didn't work. here some of my code

public function postRegister(Request $request)
    {
        $validator = $this->validator($request->all());

        if ($validator->fails()) {
            $this->throwValidationException(
                $request, $validator
            );
        }

        $this->create($request->all());

        return redirect('login');
    }

this I want to redirect to page login after user register.

I got the problem like this:

ErrorException in SessionGuard.php line 411: Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given

Note: I used laravel default scafold

Thanks in advance

Ad

Answer

postRegister() is no longer the method to override. Use this instead:

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

    if ($validator->fails()) {
        $this->throwValidationException(
            $request, $validator
        );
    }

    Auth::guard($this->getGuard())->login($this->create($request->all()));

    return redirect(route('route.after.register'));
}

Don't forget to import the Auth Facade:

use Illuminate\Support\Facades\Auth;
Ad
source: stackoverflow.com
Ad