以下代码将正确输出前3个网店:
但是当我在我的blade模板中插入分页代码时:
我遵循这里的文档: https://laravel.com/docs/5.4/pagination 该文档与it技术有关,它介绍了关于Laravel 5.4中分页的用法。
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);
}
Blade模板:
<ul class="webshop-list">
@foreach($webshops as $webshop)
<li>
{{ $webshop->name }}
</li>
@endforeach
</ul>
{{ $webshops->links() }}
但是当我在我的blade模板中插入分页代码时:
{{ $category->webshops->links() }}
我遇到了以下错误:
Method links does not exist.
我遵循这里的文档: https://laravel.com/docs/5.4/pagination 该文档与it技术有关,它介绍了关于Laravel 5.4中分页的用法。
where('category_id', $category->id)
呢? - ChristofferwhereHas
而不是where
。我已经更新了代码。 - Alexey Mezenin