I want to redirect login page to home page when i already login. At the same time when I hit login route, it show me login page. I have made custom login page. Where I need to change?
Asked
Active
Viewed 2,385 times
1
Marcin Nabiałek
- 109,655
- 42
- 258
- 291
Mujahidur Rahman Mithun IUB
- 189
- 1
- 16
-
Possible duplicate of [Laravel redirect back to original destination after login](https://stackoverflow.com/questions/15389833/laravel-redirect-back-to-original-destination-after-login) – iamvinitk Dec 13 '17 at 09:28
-
Thanks . but what is the file name which I have to change? – Mujahidur Rahman Mithun IUB Dec 13 '17 at 09:32
3 Answers
2
You should put your login route into guest middleware something like this:
Route::group(['middleware' => 'guest'], function () {
// Authentication Routes...
Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
});
and in app/Http/Middleware/RedirectIfAuthenticated.php you can define where user should be redirected in such case if you don't want to use defaults.
Marcin Nabiałek
- 109,655
- 42
- 258
- 291
0
Check Auth::user() condition in that
if(Auth::user())
//home page
else
//login page
I hope this helps you.
Shekhar Chikara
- 3,786
- 2
- 29
- 52
Niket Joshi
- 739
- 5
- 23
-1
Asyou can read in the official documentation you can set a custom redirect path directly in Login- ,Register- and ResetPasswordController in App\Http\Controllers\Auth.
Simply add protected $redirectTo = 'your/custom/path'; to the top of the controller. In your case it should be the LoginController:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = 'your/redirect/path';
// other stuff...
}
This should work for already logged in users as well as for not-logged-in users.
Brotzka
- 2,959
- 4
- 35
- 56