I have a problem. When guest is on the page, and want login. Laravel redirect on main page after login. How I can do, when guest login save page where he was and redirect there?
Middleware auth:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null $guard
* @return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (!Auth::guard($guard)->check()) {
return redirect()->guest('/login');
}
return $next($request);
}
}
I use default auth laravel. But back on previous page after login not working.