如果记录,Laravel 5重定向

时间:2015-12-22 06:35:28

标签: laravel

我想将用户重定向到我的自定义网址,如果他访问登录页面,并且已经登录。我将我的代码放在App\Http\Middleware\Authenticate但是无法正常工作

/**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // my code...
    }

有人可以帮助我,tks !!!!

3 个答案:

答案 0 :(得分:0)

将它放在你的控制器方法Auth :: check()

timerThreads = Stopwatch.StartNew();
var t1 = Task.Run(() => Threading1.func1());
var t2 = Task.Run(() => Threading1.func2());
var t3 = Task.Run(() => Threading1.func3());

Task.WaitAll(t1, t2, t3);
timerThreads.Stop ();
Console.WriteLine ("Time taken for Other threads: " + timerThreads.ElapsedMilliseconds);

See

答案 1 :(得分:0)

您可以在登录路线上使用访客中间件:

Route::get('login', [
    'middleware' => 'guest',
    'uses' => 'AuthController@getLogin' //or any other action you have defined
]);

这会将尝试访问登录页面的登录用户重定向到/home网址,但您可以在App \ Http \ Middleware \ RedirectIfAuthenticated.php中更改路径

答案 2 :(得分:0)

通过添加LoginController构造,它将在调用login时执行。

public function __construct()
    {
        // This will check if user is authenticated
        if (Auth::check()) {
            return redirect('/to-your-desired-location');
        }
        $this->middleware('guest')->except('logout');
    }