试图将分页添加到make表中。
每页最多10行。
我做错了,但是找不到。
但是出现此错误。
感谢您的帮助!
调用未定义的方法 Illuminate \ Database \ Query \ Builder :: pagination()
我在这里想念的是什么?
这是我的控制器:
$q = $request->q;
if ($q !== null && trim($q) !== ""){//here
$estates = \DB::table('allestates')
->paginate(10)
->where("building_name","LIKE", "%" . $q . "%")
->orWhere("address","LIKE", "%" . $q . "%")
->orWhere("company_name","LIKE", "%" . $q . "%")
->orWhere("region","LIKE", "%" . $q . "%")
->orderBy('price')->get();
if(count($estates) > 0){
return view("search", compact('estates'))->withQuery($q);
}
}
$estates = array();//here
return view("search", compact('estates'))->withMessage("No Found!");//here
和我的视图表:
<table cellspacing='0' class="table table-striped table-class" id= "table-id">
<thead>
<tr>
<th>会社名</th>
<th>物件名</th>
<th>住所</th>
<th>
<select name="price" class="pricetag">
<option value="price">販売価格</option>
<option value="old">旧価格</option>
</select>
</th>
<th class="price-hidden">
<select name="price" class="pricetag">
<option value="price">販売価格</option>
<option value="old">旧価格</option>
</select>
</th>
<th>専有面積</th>
<th>間取り</th>
<th>入居時期</th>
</tr>
</thead>
<tbody>
@foreach($estates as $estate)
<tr class="even">
<td>{{str_limit($estate->company_name, $limit = 20)}}</td>
<td><a href="{{json_decode($estate->link)}}" target="_blank">{{str_limit($estate->building_name, $limit = 20)}}</a><br/></td>
<td>{{str_limit($estate->address, $limit = 22)}}</td>
<td>{{str_limit($estate->price, $limit = 20)}}</td>
<td class="price-hidden">{{$estate->old_price}}</td>
<td>{{str_limit($estate->extend, $limit = 20)}}</td>
<td>{{str_limit($estate->rooms, $limit = 20)}}</td>
<td>{{str_limit($estate->entry, $limit = 20)}}</td>
</tr>
@endforeach
</tbody>
</table>
{{ $estate->links() }}
感谢您对我的帮助!
答案 0 :(得分:1)
我认为分页应该遵循条件。 尝试将-> get()替换为-> paginate(10)。
答案 1 :(得分:0)
您可以使用paginate(10)或simplepaginate(10)
在循环中,您必须写
@foreach($estates->all() as $estate)
并将{{$ estate-> links()}}替换为{{$ estates-> links()}}