最佳答案
select `A`.*, (select count(*) from `B` where `A`.`id` = `B`.`A_id`) as `B_count` from `A
或
\App\Models\A::withCount('b')->get();
讨论数量:
select `A`.*, (select count(*) from `B` where `A`.`id` = `B`.`A_id`) as `B_count` from `A
或
\App\Models\A::withCount('b')->get();
推荐文章: