By default if I am not logged and I try visit this in browser:
http://localhost:8000/home
It redirect me to http://localhost:8000/auth/login
How can I change to redirect me to http://localhost:8000/login
By default if I am not logged and I try visit this in browser:
http://localhost:8000/home
It redirect me to http://localhost:8000/auth/login
How can I change to redirect me to http://localhost:8000/login
Since your other question was marked as duplicate..I will try to answer it here..
First you need to change your route like
In your blade..make sure you use named route in the Login url link like
In Middleware/Authenticate.php change the redirect guest to
I wanted to do the same thing in Laravel 5.5. Handling authentication has moved to
Illuminate\Auth\Middleware\Authenticate
which throws anIlluminate\Auth\AuthenticationException
.That exception is handled in
Illuminate\Foundation\Exceptions\Hander.php
, but you don't want to change the original vendor files, so you can overwrite it with your own project files by adding it toApp\Exceptions\Handler.php
.To do this, add the following to the top of the
Handler
class inApp\Exceptions\Handler.php
:And then add the following method, editing as necessary:
Just change
return redirect()->guest('login');
toreturn redirect()->guest(route('auth.login'));
or anything else.I wanted to write this down because it took me more than 5 minutes to figure it out. Please drop me a line if you happened to find this in the docs because I couldn't.
This is Laravel 5.4 Solution:
There is a new unauthenticated() method in app/Exceptions/Handler.php which handles unauthenticated users and redirects to login path.
So change
to
Just to extend @ultimate's answer:
App\Http\Middleware\Authenticate::handle()
method and changeauth/login
to/login
.$loginPath
property to your\App\Http\Controllers\Auth\AuthController
class. Why? See Laravel source.In result you'll have this in your middleware:
And this in your AuthController:
EDIT: On Laravel 5.1, simply add protected $redirectPath = '/url/you/want'; to AuthController would do the trick.
REFER : http://laravel.com/docs/5.1/authentication#included-authenticating
On Laravel 5.1, it is completely moved to another middleware named RedirectIfAuthenticated.php under App\Http\Middleware
Hope it helps.
Authentication checks are made using middleware in Laravel 5.
And the middleware for auth is
App\Http\Middleware\Authenticate
.So, you can change it in
handle
method of the middleware.