我正在尝试拥有多个用户: 1.经理 2.员工
但是我有一个问题: 引发错误异常,消息为“标头不得包含多个标头,检测到新行”
Stacktrace:
我的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');
}
}
}
答案 0 :(得分:0)
redirectTo方法应返回url路径:
/*
LoginController.php
*/
protected function redirectTo( ) {
if (Auth::check() && Auth::user()->role == 'manager') {
return '/home';
}else {
return '/employee/index';
}
}