首页 > 解决方案 > 如何获取控制台电视/图表中的类别日期?

问题描述

错误:

方法 Illuminate\Database\Eloquent\Collection::provinces 不存在。

代码:

  $data = App\Protection::with('provinces');
    $protection = Charts::create('bar', 'chartjs')
        ->title('title')
        ->elementLabel('total')
        ->dimensions(0, 300)
        ->labels($data->provinces()
        ->pluck('title')
        ->implode(' '))
        ->values($data->pluck('benefit_kind'))
        ->responsive(false);

保护型号:

class Protection extends Model
{
protected $guarded = [];
public function user()
{
    return $this->belongsTo(User::class);
}
public function provinces()
{
    return $this->belongsToMany(Province::class);
}
public function districts()
{
    return $this->belongsToMany(District::class);
}

}

标签: laravel

解决方案


推荐阅读