Response.php 第 458 行中的 InvalidArgumentException:HTTP 状态代码“1”无效
InvalidArgumentException in Response.php line 458: The HTTP status code "1" is not valid
我正在尝试路由到管理面板,但需要管理字段 = 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.
你应该试试这个:
请更新您的句柄函数
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'));
请查看此 也
redirect helper function has the following signature:
function redirect($to = null, $status = 302, $headers = [], $secure = null)
您必须按如下方式使用重定向:
return redirect('login')->with(compact('umra'));
// OR
return redirect()->route('login', ['umra' => $umra]);
我正在尝试路由到管理面板,但需要管理字段 = 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.
你应该试试这个:
请更新您的句柄函数
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'));
请查看此
redirect helper function has the following signature:
function redirect($to = null, $status = 302, $headers = [], $secure = null)
您必须按如下方式使用重定向:
return redirect('login')->with(compact('umra'));
// OR
return redirect()->route('login', ['umra' => $umra]);