我有這個要求
$marche = March::with('attribution')->get()->where('attribution.date_attribution', '2021');
如何格式化“attribution.date_attribution”以僅檢索年份?
我嘗試使用 Carbon::parse,但出現以下錯誤:
Could not parse 'attribution.date_attribution': Failed to parse time string (attribution.date_attribution) at position 0 (a): The timezone could not be found in the database
uj5u.com熱心網友回復:
未經測驗,但你可以試試這個:
$marche = March::
with('attribution')
->whereHas('attribution', function($query){
$query->whereYear('date_attribution', '2021');
})
->get();
uj5u.com熱心網友回復:
試試這個也許:
->whereYear('attribution.date_attribution', '2021')
https://laravel.com/docs/8.x/queries#additional-where-clauses
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/394577.html
上一篇:按條件和欄位排序
