[英]Laravel5 Response “The HTTP status code ”1“ is not valid.”
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 如果我使用dd()
或var_dump()
打印查询结果,我得到结果,但如果我传递结果数据或重定向我得到一个异常,这是
"The HTTP status code "1" is not valid." “HTTP状态代码”1“无效。”
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());
}
}
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. 但请确保您拥有视图文件。
Also, in Laravel 5 it happens to me when I forget and try using named route on redirect: 此外,在Laravel 5中,当我忘记并尝试在重定向上使用命名路由时,它发生在我身上:
return redirect('users.overview', ['id' => $id]); // Error
instead of: 代替:
return redirect()->route('users.overview', ['id' => $id]);
I had the same issue. 我遇到过同样的问题。
Try using with() as in your else block : 尝试在else块中使用with():
return Redirect::to('property/search')->with(compact('properties'))
Moreover as of Laravel 5, you can simply use the redirect() helper like this: 此外,从Laravel 5开始,您可以像这样简单地使用redirect()帮助器:
return redirect('property/search')->with(compact('properties'))
I had kind of the same problem. 我有同样的问题。 As per Larvel 5.1 documentation , redirect can bring parameters this way: 根据Larvel 5.1文档 ,重定向可以通过这种方式引入参数:
return redirect('yourRoute')->with('param', 'value');
Then in the view echo the parameter: 然后在视图中回显参数:
@if (session('param'))
{{ session('param') }}
@endif
I also encountered the same situation, because you passed the wrong parameters in the Model 我也遇到了同样的情况,因为你在模型中传递了错误的参数
public static $rules = array(
'id' => 'required',
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.