我已经在我的 laravel 5.4
项目中实现了Multi-Auth
,但是每当我尝试从其他设备登录时,我都会收到此错误。
ErrorException in Response.php line 386:Header may not contain more than a single header, new line detected
现在我尝试查看该网站中的其他类似问题,但没有一个与我在登录 Controller 中所做的相匹配。
这是我的登录 Controller :
class LoginController extends Controller
{
use AuthenticatesUsers;
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
public function username()
{
return 'mobile_no';
}
protected function redirectTo( )
{
$notification = array(
'message' => 'Welcome Admin!',
'alert_type' => 'info',
'title' => Auth::user()->name
);
return redirect('/home')->with('notification', $notification);
}
}
我的 redirecTo()
函数出了什么问题?
最佳答案
这个问题已经得到解答here 。 基本上你的方法应该返回一个字符串而不是重定向响应。 这是一个例子:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
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 $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function redirectTo(){
return '/admin';
}
}
但是因为您实际上需要重定向到 View 并包含一些对您不起作用的数据。您需要的是完全覆盖重定向功能并创建您自己的 . 这是您需要做的。您可以从这里复制整个类,它应该开箱即用:)。这是代码。干杯。
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
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 $redirectTo = '/';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
//this should not be included
//$this->middleware('guest')->except('logout');
}
//public function redirectTo(){
// return '/admin';
//}
protected function authenticated()
{
$notification = array(
'message' => 'Welcome Admin!',
'alert_type' => 'info',
'title' => Auth::user()->name
);
return redirect('/home')->with('notification', $notification);
}
}
关于php - 拉维尔 |错误: Header may not may not contain more than a single header,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022656/