I am using Laravel Framework 5.4.10, and I am using the regular authentication that
php artisan make:auth
provides. I want to protect the entire app, and to redirect users to /themes after login.
I have 4 controllers: ForgotPasswordController.php, LoginController.php, RegisterController.php and ResetPasswordController.php. I have edited this line into the last three:
protected $redirectTo = '/themes';
This is the first line in my routes/web.php:
Auth::routes();
I have added this function in my Controller.php:
public function __construct()
{
$this->middleware('auth');
}
I have edited app/Http/Middleware/RedirectIfAuthenticated.php, so that the handle function looks like this:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/themes');
}
return $next($request);
}
It's all fine, except when I click the Login button, I get redirected to "/", not "/themes". If I don't require authentication in the controllers (no __contruct function in Controller.php file), I get redirected OK at login. What am I doing wrong?
That's what i am currrently working, what a coincidence.
You also need to add the following lines into your LoginController