Laravel eloquent get relation count

前端 未结 5 2022
温柔的废话
温柔的废话 2021-02-05 00:29

I use Laravel 5.3.

I have 2 tables :

Articles
---------
id
cat_id
title

And

Category
---------
id
parent_id
title
         


        
5条回答
  •  鱼传尺愫
    2021-02-05 01:20

    you can use withCount(). It is available from 5.3 version

    for more info about eloquent visit : https://laravel.com/docs/5.3/eloquent-relationships

提交回复
热议问题