laravel - 如何获取控制台电视/图表中的类别日期?
问题描述
错误:
方法 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);
}
}
解决方案
推荐阅读
- javascript - 一次在控制器中实例化服务类,而不是在每个方法上。性能和内存权衡
- reactjs - 如何将 React Native Async-Storage 与 Redux 一起使用?
- python - 我正在尝试用球体在海龟中制作游戏
- python - 如何在不暂停 tkinter 中的整个窗口的情况下暂停特定功能?
- list - 为什么清除列表会清除第一个?
- php - 从字符串中的引号中提取时如何包含等号和引号?
- push-notification - 推送通知可行性
- spring - @RepositoryRestResource 将 findAll 覆盖为仅登录用户
- c# - 如何使用 Selenium 在两个 HTML5 画布元素之间拖动一个元素?
- material-ui - 测试材料 Ui (v5) 抽屉 - 无法读取 null 的属性“scrollTop”