我想使用 hasManyThrough 关系在类别页面上显示分页
I want to show pagination on Category Page using hasManyThrough relationship
我的类别页面显示使用 hasManyThrough 关系在特定类别中提交的网站。
我想在类别页面上对结果进行分页。我如何在我的控制器中使用分页?
类别模型
class Category extends Model
{
public $timestamps = false;
protected $fillable = ['name','category_id'];
public function subcategories()
{
return $this->hasMany(Subcategory::class);
}
public function websites()
{
return $this->hasManyThrough(Website::class, Subcategory::class);
}
}
控制器
public function show(Category $category)
{
return view('category',compact('category'));
}
```
可能是这样的:
public function show(Category $category){
return view('category')
->with('category', $category)
->with('websites', $category->websites()->paginate(10))
->with('subcategories', $category->subcategories);
}
我的类别页面显示使用 hasManyThrough 关系在特定类别中提交的网站。 我想在类别页面上对结果进行分页。我如何在我的控制器中使用分页?
类别模型
class Category extends Model
{
public $timestamps = false;
protected $fillable = ['name','category_id'];
public function subcategories()
{
return $this->hasMany(Subcategory::class);
}
public function websites()
{
return $this->hasManyThrough(Website::class, Subcategory::class);
}
}
控制器
public function show(Category $category)
{
return view('category',compact('category'));
}
```
可能是这样的:
public function show(Category $category){
return view('category')
->with('category', $category)
->with('websites', $category->websites()->paginate(10))
->with('subcategories', $category->subcategories);
}