Laravel |错误:标题可能不包含多个标题

时间:2017-05-17 10:45:25

标签: php laravel http http-headers laravel-5.4

我已在Multi-Auth项目中实施laravel 5.4,但每当我尝试从其他设备登录时,我都会收到此错误消息。

  

Response.php第386行中的ErrorException:标题可能不包含更多内容   比单个标题,检测到新行

现在我已经尝试在这个网站上查找其他类似的问题,但它们都没有与我在登录控制器中所做的相匹配。

这是我的登录控制器:

   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()功能出了什么问题?

1 个答案:

答案 0 :(得分:1)

这个问题已经回答here。 基本上你的方法应该返回一个String而不是一个Redirect响应。 这是一个例子:

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';
     }


}

但是因为您实际上需要重定向到视图并包含一些不适合您的数据。您需要的是一起覆盖重定向功能,只需创建自己的功能。 这是你需要做的。你可以从这里复制整个类,它应该开箱即用:)。这是代码。干杯。

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);
 }

}