我试图发送以下查询的集合:
$monthly_report_chart = DB::table("transactions")
->select(DB::raw("Date(updated_at) as today"),DB::raw("SUM(collected_today) as sum"))
->groupBy(DB::raw('Date(updated_at)'))
->where(DB::raw('Month(updated_at)'),'=',$month)
->get();
我想像这样访问 javascript 中的集合:
{!! json_encode($monthly_report_chart->today) !!}
但它抛出以下错误:
Property [today] does not exist on this collection instance
如何在 javascript 中访问集合实例? 谢谢!
最佳答案
如果您的收藏有 today 属性,您可以在收藏上使用 pluck。 例如
{!! json_encode($monthly_report_chart->pluck('today')) !!}
关于php - 将集合实例作为 javascript 变量访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48745609/