模型:
class Category extends Model
{
public function trainings()
{
return $this->hasMany('App\Training');
}
}
Controller :
return view('category', [
'trainings' => Category::find(1)->trainings->paginate(10)
]);
我收到
Call to undefined method Illuminate\Database\Eloquent\Collection::paginate()
错误。如何在Laravel 5中对雄辩的集合进行分页?
最佳答案
您必须调用trainings
作为方法:
Category::find(1)->trainings()->paginate(10)
// ^^
关于php - Laravel 5-Paginate Eloquent系列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29393816/