php - 将集合实例作为 javascript 变量访问?

标签 php laravel laravel-5

我试图发送以下查询的集合:

 $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/

相关文章:

php - Laravel - 归档数据,删除和插入到另一个表

php - 如何匹配Elasticsearch中包含破折号(-)的条目

php - MySQL 行未找到但确实存在

php - 在种子 laravel 中没有正确地从环境变量中提取

php - Laravel Gmail 不工作, "Username and Password not accepted. Learn more..."

jquery - 在 Laravel 中显示 JQuery 模态?

php - 为什么如果我不在表单末尾放置 {{csrf_field()}} (在 Laravel 5 View 中),我会收到 TokenMismatchException?

php - Laravel - 以 .php 结尾的重定向捕获/重定向 Urls

php - 我找不到用于设置 "DOMPDF_UNICODE_ENABLED"true 的 dompdf_config.inc.php 或 dompdf_config.custom.inc.php

php - 获取sql错误PHP