在 laravel 中使用分页

use paginate with has in laravel

我正在尝试从查询中获取结果 使用分页并查看使用下面的代码我减少了代码以使其被接受 $类别=Course_category::有('classe')->分页(2);

 @foreach ($categories as $categorie)
 @foreach ($categorie->classe as $item )
 @endforeach
 @endforeach
 {{ $categories->links('pagination::bootstrap-4') }}

也许你的意思是:

$categories = Course_category::with(['classe'])->paginate(2);

你能试试这样吗:

$categories = Course_category::with(['classe' => function ($q) {
            $q->paginate(2);
            //or something like $q->orderBy(stuff)->take(2);
        }]);