我正在使用laravel 5.4
,所以我正在嘗試計算兩個模型“Person”和“Permanance”之間的關系數量,所以這就是它在我的控制器中的呼叫方式,
$persons = Person::all()->withCount('Permanance')->get();
這是我得到的錯誤
(1/1) 壞方法呼叫例外
方法 withCount 不存在。在 Collection->__call('withCount', array('Permanance')) 的 Macroable.php 第 74 行中 PermanancesController.php 第 41 行
uj5u.com熱心網友回復:
您應該直接用作靜態方法withCount而不使用該all()方法,如Laravel Docs中所述
$posts = Post::withCount('comments')->get();
uj5u.com熱心網友回復:
請撥打以下電話,
$persons = Person::withCount('Permanance')->get();
uj5u.com熱心網友回復:
你犯了一個小錯誤
Person::withCount('Perfomance')->get();
all()從中間移除
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/460825.html
上一篇:無法捕獲Sequelize在包羅萬象的中間件中引發的錯誤
下一篇:SQLSTATE[23000]:完整性約束違規:1062鍵“user_username_unique”的重復條目“asdf”(SQL:更新“用戶”設定“用戶名”=asdf
