Response.php第458行中的InvalidArgumentException:HTTP状态代码“ 1”无效

时间:2019-01-09 06:32:02

标签: laravel laravel-5.2

我试图路由到管理面板,但需要将admin field = 1否则重定向到登录页面,我在内核中创建了中间件IsUserAdmin和我的代码:

'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
    ],

    'admin'=> [
        \App\Http\Middleware\Authenticate::class,
        \App\Http\Middleware\IsUserAdmin::class,
    ],

和中间件:

public function handle($request, Closure $next)
{
    if(Auth::user()->admin != 1)
    {
        $umra = package_model::where('package_type','=','1')->orderby('id','desc')->skip(0)->take(6)->get();
        $tours = package_model::where('package_type','=','1')->orderby('id','desc')->skip(0)->take(5)->get();

        $last_tour = package_model::where('package_type','=','2')->orderby('id','desc')->skip(0)->take(1)->get();
        $last_tours = package_model::where('package_type','=','3')->orderby('id','desc')->skip(0)->take(4)->get();

        $all_package = package_model::orderby('id','desc')->skip(0)->take(15)->get();
        $allKey = keywords_model::orderby('id','desc')->get();
        $categories = category_model::where('parent_id','=','0')->orderby('id','asc')->skip(0)->take(5)->get();

        return redirect('login', ['umra'=>$umra,'tours'=>$tours,'last_tour'=>$last_tour,'last_tours'=>$last_tours,'all_package'=>$all_package,'allKey'=>$allKey,'categories'=>$categories]);
    }
    return $next($request);
}

和路线

Route::group(['middleware' => ['web','admin']], function (){
Route::get('/adminpanel', 'Admincontroller@index');
Route::get('/adminpanel/users', 'UsersController@index');
Route::get('/adminpanel/addpackage', 'Admincontroller@addnew');

});

 InvalidArgumentException in Response.php line 458: The HTTP status code "1" is not valid.

2 个答案:

答案 0 :(得分:0)

您应该尝试以下操作:

请更新您的句柄功能

return redirect('login', ['umra'=>$umra,'tours'=>$tours,'last_tour'=>$last_tour,'last_tours'=>$last_tours,'all_package'=>$all_package,'allKey'=>$allKey,'categories'=>$categories]); // login means your view file path

收件人

return view('login', compact('umra','tours','last_tour','last_tours','all_package','allKey','categories'));

也请对此link进行审查

答案 1 :(得分:0)

redirect辅助函数具有以下signature

function redirect($to = null, $status = 302, $headers = [], $secure = null)

您必须使用重定向,如下所示:

return redirect('login')->with(compact('umra'));

// OR

return redirect()->route('login', ['umra' => $umra]);