i am using laravel 5.1.8. i am making a login/registration system. i made a controller named AdminController and protect it with middleware.
but i am using laravel's default AuthController which methods and classes are located in different locations. where routes are:
Route::Controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController'
]);
get('admin', 'AdminController@index');
get('profile', 'AdminController@profile');
get('article', 'AdminController@article');
users cannot access AdminController without logging in. its redirected to login page. but i want, if a logged in user typed the address of login page or registration on the address bar of browser, the page will redirected to AdminController.
when i try to do this, it looking for '/home' and gives errors. i want to make it '/admin'.
if(Auth::check()) { return View::make('view_page'); } return Redirect::route('login')->withInput()->with('errmessage', 'Please Login to access restricted area. ');
By default laravel will redirect a user to the home page like so: protected $redirectTo = '/home'; To change that default behaviour, add the following code in App/Http/Controllers/Auth/LoginController. php . This will redirect users (after login) to where ever you want.
Laravel 8 Auth Redirection Using redirectTo() Method You can either remove the $redirectTo variable or leave it as it will be simply overridden by the redirectTo() method.
“check if user is logged in laravel 8” Code Answer'sif (Auth::check()) { // The user is logged in... }
go to
App\Http\Middleware\RedirectIfAuthenticated
then change it from
public function handle($request, Closure $next)
{
if ($this->auth->check()) {
return redirect('/home');
}
return $next($request);
}
to
public function handle($request, Closure $next)
{
if ($this->auth->check()) {
return redirect('/admin');
}
return $next($request);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With