简体   繁体   中英

Laravel 5.1 Redirect after Registration not working

I just want to override the postRegister() method to avoid Laravel to login the user automatically after registration. So I did inside the AuthController.php :

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

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

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

    return redirect('test');
}

Laravel create the user without Login like I want, the problem is in the redirect line. For some very strange reason the always redirect the user to the '/auth/login' route. I commented all my middlewares just to make sure that is not some middleware doing the redirect:

    protected $routeMiddleware = [
    'auth' => \CapTable\Http\Middleware\Authenticate::class,
    'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
    'guest' => \CapTable\Http\Middleware\RedirectIfAuthenticated::class,
    'activated' => \CapTable\Http\Middleware\UserActive::class,
];

I tried php artisan clear-compiled and php artisan cache:clear and php artisan clear:config to clean all possible cache or config files but Laravel still doing the redirect to /auth/login .

After some debug in the code I saw that its reading my new function who overrides the original in vendor.

I really without ideas, someone here had some similar issue or know how can I find out whats is going on here ?

PS test is just a alias to the route that I want to redirect the user.

Thanks Guys

Try giving the exact route as defined in your route.php

public function postRegister(Request $request) {

       // your code here

return redirect('/login'); //This is the actual route as defined and not an alias

}

If not, try using return Redirect::to('http://example.com/login'); or return Redirect::back();

The problem wasn't in the backend. I had some redirection in my frontend (Angular.js) that was overriding the Laravel redirection.

window.location = '/auth/login';

But I learned a important lesson: Always check the frontend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM