$posts = App\Post::withCount([
'comments',
'comments as pending_comments_count' => function ($query) {
$query->where('approved', false);
}
])->get();
echo $posts[0]->comments_count;
echo $posts[0]->pending_comments_count;
Laravel 黑科技:Eloquent 裡的 withCount
相關文章
- Laravel Eloquent 用法Laravel
- Laravel eloquent 的事務與事件Laravel事件
- Laravel 5 Eloquent cast arrayLaravelAST
- Laravel Eloquent 的關係模型聯動Laravel模型
- Laravel 原始碼閱讀 - EloquentLaravel原始碼
- 20個Laravel Eloquent 使用技巧Laravel
- 5 個 Laravel Eloquent 小技巧Laravel
- 黑科技開戶神器黑科技開戶神器黑科技開戶神器黑科技開戶神器黑科技開戶神器
- 【譯】20個 Laravel Eloquent 小技巧Laravel
- Laravel 文件閱讀:Eloquent 起步(下篇)Laravel
- 你可能不知道的 Laravel Eloquent 操作Laravel
- 20 個 Laravel Eloquent 必備的實用技巧Laravel
- 提高 Laravel Eloquent 查詢的5個小技巧Laravel
- 8 張圖掌握 Laravel 的 Eloquent 關聯關係Laravel
- Laravel 原始碼分析——Eloquent 的工作原理簡析Laravel原始碼
- Laravel Eloquent 模型關聯速查表Laravel模型
- Laravel Database——Eloquent Model 更新關聯模型LaravelDatabase模型
- Laravel Database——Eloquent Model 原始碼分析(下)LaravelDatabase原始碼
- Laravel Database——Eloquent Model 原始碼分析(上)LaravelDatabase原始碼
- Laravel transaction : Laravel 的事務是不支援 eloquent 的? 要用 DB::的方式?為啥Laravel
- 黑袋子——一個擁有黑科技的APPAPP
- 幾個CSS的黑科技CSS
- Laravel Eloquent中的 懶載入VS即時載入Laravel
- Laravel & Eloquent 模型設定 created_at 和 updated_atLaravel模型
- Laravel Eloquent 分表方法並使用模型關聯Laravel模型
- Laravel Eloquent 關聯模型查詢快取資料Laravel模型快取
- 使用 Laravel Eloquent 構造器讓模型更簡潔Laravel模型
- 重構後的Firefox網路監視工具,裡邊加了什麼黑科技?Firefox
- 分享行業“黑科技”行業
- 你可能不知道的 10 個 Laravel Eloquent 的隱藏特性Laravel
- 分享 10 個你可能不知道的 Laravel Eloquent 小技巧Laravel
- 史上最全的谷歌公司那些黑科技谷歌
- laravel Eloquent模型 關於模型關聯屬性獲取Laravel模型
- Laravel Eloquent 分表方法 支援create 和with等靜態宣告model的方法Laravel
- javascript黑科技之高效填充JavaScript
- CSS黑科技補充篇CSS
- Laravel裡的那些坑 - OptionalLaravel
- 如何用好 Go 的測試黑科技Go