Laravel重定向在递归函数调用中不起作用

时间:2018-08-14 19:02:50

标签: php laravel

我的LoginController(Laravel)中出现问题,重定向调用无法按预期方式工作,而是生成空白页面。

我的代码如下:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

use App\User;

class LoginController extends Controller
{
    /**
     * Handle an authentication attempt.
     *
     * @param  \Illuminate\Http\Request $request
     *
     * @return Response
     */
    public function authenticate(Request $request)
    {
        $credentials = $request->only('email', 'password');

        if (Auth::attempt($credentials)) {
            // Authentication passed...

            //  dd("test") here outputs "test" but the redirect doesn't work

            return redirect()->route('dashboard');
        }

        $this->doSomethingElse($request);
    }

    private function doSomethingElse(Request $request)
    {
        // do stuff...

        return $this->authenticate($request);
    }

    public function logout(Request $request)
    {
        Auth::logout();

        return redirect('/');
    }
}

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

您的web.php中是否有名为“仪表板”的路由?像这样

   Route::get('/dashboard', function () {
      return view('yourview');
   })->name('dashboard');

希望这对您有帮助...