Laravel5 Response “The HTTP status code ”1“ is not valid.”

青春壹個敷衍的年華 提交于 2020-01-01 08:57:20

问题


I have large but simple join query for large data. If i print query result using dd() or var_dump() i get result, but if i pass result data or redirect i get an exception which is

"The HTTP status code "1" is not valid."

Here is action code:

public function postSearch(Request $request)
{
    $min_price  = !empty($request['min_price']) ? $request['min_price'] : 500;
    $max_price  = !empty($request['max_price']) ? $request['max_price'] : 50000000000;

    $properties = DB::table('properties')
                ->join('addresses', function($join) {
                    $join->on('properties.id', '=', 'addresses.property_id');
                })
                ->where('status', '=', 1)
                ->where('category', '=', $request['search_category'])
                ->where('type', '=', $request['contract'])
                ->where('city', '=', $request['search_city'])
                ->where('area', '=', $request['property_area'])
                ->where('bed_room', '=', $request['search_bedroom'])
                ->where('bath_room', '=', $request['bath_room'])
                ->whereBetween('price', [$min_price, $max_price])
                ->orderBy('properties.updated_at', 'desc')
                ->paginate(15);
    try {
        if(!empty($properties))
        {
            return Redirect::to('property/search', compact('properties'));
        }
        else
        {
            return Redirect::to('/')->with('message', PropertyHelper::formatMessage(trans('property.property_not_found'), 'danger'));
        }
    }
    catch(\Exception $ex) {
        dd($ex->getMessage());
    }

}

回答1:


I guess you try to show the search results after searching. The problem is this line.

return Redirect::to('property/search', compact('properties'));

After you get the search result you should call a view, not redirect.

return view('property.search', compact('properties'));

But make sure you have the view file.

Source




回答2:


Also, in Laravel 5 it happens to me when I forget and try using named route on redirect:

return redirect('users.overview', ['id' => $id]); // Error

instead of:

return redirect()->route('users.overview', ['id' => $id]);



回答3:


I had the same issue.

Try using with() as in your else block :

return Redirect::to('property/search')->with(compact('properties'))

Moreover as of Laravel 5, you can simply use the redirect() helper like this:

return redirect('property/search')->with(compact('properties'))



回答4:


I had kind of the same problem. As per Larvel 5.1 documentation, redirect can bring parameters this way:

return redirect('yourRoute')->with('param', 'value');

Then in the view echo the parameter:

@if (session('param'))
    {{ session('param') }}
@endif



回答5:


I also encountered the same situation, because you passed the wrong parameters in the Model

public static $rules = array(       
    'id' => 'required',
);


来源:https://stackoverflow.com/questions/29569530/laravel5-response-the-http-status-code-1-is-not-valid

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!