型号:
class Category extends Model
{
public function trainings()
{
return $this->hasMany('App\Training');
}
}
控制器:
return view('category', [
'trainings' => Category::find(1)->trainings->paginate(10)
]);
我收到Call to undefined method Illuminate\Database\Eloquent\Collection::paginate()
错误。
如何在Laravel 5中对Eloquent Collection进行分页?
答案 0 :(得分:16)
您必须将trainings
称为方法:
Category::find(1)->trainings()->paginate(10)
// ^^