【发布时间】:2021-11-29 11:25:35
【问题描述】:
我在我的 Laravel 8.54 项目中使用原始 SQL 语句,例如:
$data = DB::select("SELECT * FROM ..WHERE..= '$number' AND.. like '$SelectedMonth%' ORDER BY ..ASC");
然后我使用 Laravel Query Builder 将它们转换为:
$data = DB::table("..")
->select("..")
->where("..", "=", $number)
->where("..", "like", $SelectedMonth.'%')
->orderBy("..", "asc")
->get();
在更改之前,SQL 查询返回了一个对象数组,我可以使用 Sort() 和其他一些函数。
现在我收到错误:sort(): Argument #1 ($array) must be of type array, Illuminate\\Support\\Collection given 和 Expected type 'array'. Found 'Illuminate\Support\Collection'
如何将给定的结果转换回数组?
谢谢
【问题讨论】: