4
如何在每個項目中添加新字段,我已經使用put()
但它只添加在最後一個項目上。Laravel如何在查詢結果中添加新字段
return self::where('latest', 1)
->where('competitionId',$competitionId)
->orderBy('won','desc')
->orderBy('teamName','asc')
->get(['teamName','played','won','lost','percentage', 'streak'])
->put('test', ['123', '345'])
->toJson();
結果:
{
"0": {"teamName": "A"},
"1": {"teamName": "B"},
"2": {"teamName": "C", "test": ['123', '345']},
}
預期輸出:
{
"0": {"teamName": "A", "test": "qwerty"},
"1": {"teamName": "B", "test": "qwerty"},
"2": {"teamName": "C", "test": "qwerty"},
}
集合{#389▼ #items:數組:8 [▼ 0 =>空 1 =>空 2 =>空 3 =>空 4 =>空 5 =>空 6 =>空 7 =>空 ] } – PenAndPapers
它變成所有項目的回報null – PenAndPapers
我發現'return $ item'; –