简体   繁体   English

Laravel5响应“HTTP状态代码”1“无效。”

[英]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. 但请确保您拥有视图文件。

Source 资源

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.

相关问题 Laravel 5.1-redirect-> intended()返回“ HTTP状态代码“ 1”无效。” - Laravel 5.1 - redirect->intended() returns “The HTTP status code ”1“ is not valid.” Laravel HTTP状态码“ 1”无效错误 - Laravel HTTP status code “1” is not valid error 给出错误HTTP状态代码“ 600”无效。 提交ajax后 - Giving error The HTTP status code “600” is not valid. after submitting ajax 调用 Laravel5 中未定义的方法 Illuminate\\Http\\Response::json() - Call to undefined method Illuminate\Http\Response::json() in Laravel5 如何在 Laravel response()->download() 中返回 Http 响应状态码? - How To Return a Http Response Status Code in Laravel response()->download()? Laravel - 如何从控制器设置 HTTP 响应状态代码 - Laravel - How to set HTTP response status code from Controller 如何在Laravel 5中添加HTTP状态代码和状态文本以使用ellipsesynergie / api-response响应? - How to add HTTP Status code and status text in to response with ellipsesynergie/api-response In Laravel 5? Laravel 抛出错误“方案`javascript` 无效。 它应该是 `http` 或 `https`” - Laravel throws error “The scheme `javascript` isn't valid. It should be either `http` or `https`” 强制Laravel响应状态码 - Forcing Laravel response status code 没有消息的Laravel响应状态代码 - Laravel response status code with no message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM