多重身份验证中的标题问题

时间:2018-12-18 10:53:07

标签: php laravel-5.7

我正在尝试拥有多个用户: 1.经理 2.员工

但是我有一个问题: 引发错误异常,消息为“标头不得包含多个标头,检测到新行”

Stacktrace:

4 ErrorException in E:\ xamp \ htdocs \ TMS \ vendor \ symfony \ http-foundation \ Response.php:341

E:\ xamp \ htdocs \ TMS \ vendor \ symfony \ http-foundation \ Response.php:341中的3个标头

2 Symfony \ Component \ HttpFoundation \ Response:sendHeaders in E:\ xamp \ htdocs \ TMS \ vendor \ symfony \ http-foundation \ Response.php:375

1 Symfony \ Component \ HttpFoundation \ Response:在E:\ xamp \ htdocs \ TMS \ public \ index.php:58中发送

E:\ xamp \ htdocs \ TMS \ server.php:21中的0 require_once

我的LoginController.php

<?php

namespace App\Http\Controllers\Auth;
use Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected function redirectTo( ) {
    if (Auth::check() && Auth::user()->role == 'manager') {
        return redirect('/home');
    }

    else {
        return redirect('/employee/index');
    }
}

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }
}

我的manager.php

<?php

namespace App\Http\Middleware;
use Auth;
use Closure;

class Manager
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
   function handle($request, Closure $next)
{
    if (Auth::check() && Auth::user()->role == 'manager') {
        return redirest('/home');
    }

    else {
        return redirect('/employee/index');
    }
}
}

我的employee.php

<?php

namespace App\Http\Middleware;
use Auth;
use Closure;

class Employee
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
   function handle($request, Closure $next)
{
    if (Auth::check() && Auth::user()->role == 'employee') {
        return redirect('/employee/index');
    }

    else {
        return redirect('/home');
    }
}


}

1 个答案:

答案 0 :(得分:0)

redirectTo方法应返回url路径:

/*
LoginController.php
*/
protected function redirectTo( ) {
   if (Auth::check() && Auth::user()->role == 'manager') {
      return '/home';
   }else {
      return '/employee/index';
   }
}