Php laravel:将对象传递到d3.cal-heatmap

Php laravel:将对象传递到d3.cal-heatmap,php,laravel,laravel-5,laravel-5.4,Php,Laravel,Laravel 5,Laravel 5.4,我想构建一个包含unix日期时间值出现次数的数据变量 i、 e 我的错误是,在视图中,我使用了未定义的常量数据,即假定的“数据” public function showStatistics() { $job_post_date = Emploi::where('language', 'EN')->pluck('POSTDATE'); $unix_time = array(); for ($i=0; $i < count($job_post_date) ;

我想构建一个包含unix日期时间值出现次数的数据变量

i、 e

我的错误是,在视图中,我使用了未定义的常量数据,即假定的“数据”

public function showStatistics()
{
    $job_post_date = Emploi::where('language', 'EN')->pluck('POSTDATE');
    $unix_time = array();

    for ($i=0; $i < count($job_post_date) ; $i++) { 
        $unix_time[$i] = strtotime($job_post_date[$i]);
    }

    $datas = array_count_values($unix_time);
    $datas = json_encode($datas);

    return view('emploi.stats', ['datas' => $datas]);
}
我在模板中得到一个错误:{{datas}

使用

data:  {!! $datas !!}
而不是

data:  {!! datas !!}

您错过了美元符号,这使得PHP假定它是一个常量(您没有声明)。

谢谢@lessugar!您可以将其更新为{!!$datas!!},使其成为正确的javascript对象吗。{“1497571200”:3,“1497484800”:5,…},否则它将逃避引号。在你的帖子上也做了。
data:  {!! $datas !!}
data:  {!! datas !!}