我有這個基本的資料庫模型,我想按角色名稱對所有用戶進行分組,即我想列出兩個集合中的管理員用戶和其他用戶。
資料庫模型

我試圖這樣做,但它只適用于一對多的關系
User::with('roles’)->get()->groupBy(‘roles.name’);
uj5u.com熱心網友回復:
使用通配符*跳過陣列:
User::with('roles')->get()->groupBy('roles.*.name');
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/400180.html
上一篇:過濾表以排除特定行
