ahmed
ahmed

Reputation: 165

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

I am trying to make routing to admin panel but need to be admin field = 1 otherwise redirect to the login page, I made middleware IsUserAdmin and my code in the kernel:

'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,
    ],

and middleware:

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

and route

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.

Upvotes: 1

Views: 1158

Answers (2)

Prashant Pokhriyal
Prashant Pokhriyal

Reputation: 3827

redirect helper function has the following signature:

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

You have to use redirect as follows:

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

// OR

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

Upvotes: 0

user10186369
user10186369

Reputation:

You should try this:

Please update your handle function

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

To

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

Please review this link also

Upvotes: 2

Related Questions