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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29569530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:28:19  来源:igfitidea点击:

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

phpsymfonylaravellaravel-4laravel-5

提问by mininoz

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

}

回答by mininoz

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

来源

回答by Rav

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

回答by kirly

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'))

回答by a.barbieri

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

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

Then in the view echo the parameter:

然后在视图中回显参数:

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

回答by ?inh ??c L?u

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

我也遇到过同样的情况,因为你在Model中传入了错误的参数

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