3 回答
TA贡献1816条经验 获得超6个赞
您将查询结果作为“results”返回,因此在视图中您需要将其作为“$results”访问。在错误中它说未定义的变量结果。里面没有“s”。所以参考错误返回的代码行,检查变量命名是否正确。
TA贡献2037条经验 获得超6个赞
在控制器中:
public function delhi_property()
{
$data = DB::table('property')->where('city', 'Delhi')->orWhere('city', 'New Delhi')->get();
return view('index', compact('data'));
}
在刀片文件中:
<h3>( {{ $data->count() }} ) Properties</h3>
或者
<h3>( {{ count($data) }} ) Properties</h3>
TA贡献1779条经验 获得超6个赞
I am modifying your query a bit, will achieve the same result efficiently
public function delhi_property()
{
$cityResults = DB::table('property')->whereIn('city', ['Delhi','New Delhi'])->get();
return view('index',compact('cityResults'));
}
在您看来,您可以按如下方式访问计数:
<h3>{{ $cityResults->count() }} Properties</h3>
- 3 回答
- 0 关注
- 131 浏览
添加回答
举报