laravel - Laravel - 如何在 LaravelChart 模型中添加 where 子句
问题描述
在我的 Laravel-5.8 中,我有以下代码:
$chart_settings = [
'chart_title' => 'Users By Months',
'chart_type' => 'line',
'report_type' => 'group_by_date',
'model' => 'App\\User',
'group_by_field' => 'last_login_at',
'group_by_period' => 'month',
'aggregate_function' => 'count',
'filter_field' => 'last_login_at',
'column_class' => 'col-md-12',
'entries_number' => '5',
];
$chart = new LaravelChart($chart_settings);
如何将此 where 子句添加到上面的代码中('model' => 'App\User',)
where('hr_status', 0)->where('company_id', $userCompany)
谢谢
解决方案
您可以使用where_raw来指定自定义 where 条件
$chart_settings = [
'chart_title' => 'Users By Months',
'chart_type' => 'line',
'report_type' => 'group_by_date',
'model' => 'App\\User',
'group_by_field' => 'last_login_at',
'group_by_period' => 'month',
'aggregate_function' => 'count',
'filter_field' => 'last_login_at',
'column_class' => 'col-md-12',
'entries_number' => '5',
'where_raw' => 'hr_status = 0 AND company_id ='.$userCompany
];
$chart = new LaravelChart($chart_settings);
推荐阅读
- agora.io - 如何减少在agora上开始通话录音的延迟
- android - Android apk 版本自动更新
- python - 使用 sklean 拟合数据的高斯混合模型
- python - Python:更有效的方法
- java - 无法解析“地图”中的方法“条目”
- reactjs - 如何在 saga 文件中获取 redux 状态
- android - 拒绝时授予 Android 12 BLUETOOTH_CONNECT 权限
- docker - 为什么当我进入 Kubernetes pod 时执行失败:container_linux.go:380?
- sql-server - 如何从同一列 SQL Server 中的不同值组求和(MAX 值)
- javascript - nw.js 使用它打印后关闭窗口