【发布时间】:2018-06-09 06:39:02
【问题描述】:
以下代码将正确输出前3个网店:
public function category($slug) {
$category = Category::select()
->where('slug', $slug)
->with(['webshops' => function ($query) {
$query->groupBy('webshops.id')
->where('active', 1)
->orderBy('webshops.name')
->with(['brands' => function ($query) {
$query->where('active', 1)
->where('replace_by', NULL)
->orderBy('name');
}])
->paginate(3);
}])
->first();
if(!$category)
abort(404);
$data['title'] = "Tøjbutikker der forhandler ". $category->name;
$data['category'] = $category;
$data['webshops'] = $category->webshops;
return view('pages/category', $data);
}
刀片模板:
<ul class="webshop-list">
@foreach($webshops as $webshop)
<li>
{{ $webshop->name }}
</li>
@endforeach
</ul>
{{ $webshops->links() }}
但是当我在刀片模板中插入分页代码时:
{{ $category->webshops->links() }}
我收到以下错误:
Method links does not exist.
我正在关注此处的文档: https://laravel.com/docs/5.4/pagination
【问题讨论】:
标签: php mysql laravel pagination laravel-5.4