php - 如何在 laravel 中的 updateOrCreate 上按月和年过滤?
问题描述
如何created_at
在 Laravel 中过滤月份和年份updateOrCreate()
?
$statistik = Statistik::updateOrCreate(
[
'kode_kantor' => $map->kode_kantor,
'created_at' => whereYear('created_at', '=', date('Y-m-d')),
'created_at' => whereMonth('created_at', '=', date('Y-m-d'))
]
)->increment('poin_kunjungan');
解决方案
您正在寻找的东西不能由updateOrCreate()
. 您将不得不进行手动检查。例如:
$statistik = Statistik::where('kode_kantor', $map->kode_kantor)
->whereYear('created_at', '=', date('Y-m-d'))
->whereMonth('created_at', '=', date('Y-m-d'))
->first();
if(! $statistik) {
$statistik = Statistik::create([
'kode_kantor' => $map->kode_kantor
]);
}
$statistik->increment('poin_kunjungan');
推荐阅读
- jenkins - 将 YAML 文本的子集复制到单独的文件中,然后在处理时出现语法错误
- vue.js - Vue Multiselect多个条件删除选择
- javascript - 如何等待视图组件的 Vuex 状态初始化?
- python - Mule 3.8 错误:ImportError: No module named auth
- c++ - static_casting int to enum 而不是直接初始化它有什么好处吗?
- c# - 带空参数的 Json 构造函数
- sql - 如何在不指定记录的情况下获取特定记录的最新日期?
- javascript - 创建的 pdf 不会使用 jsPDF() 进行换行
- c# - 从页面访问时静态类代码是否安全/线程安全?
- google-apps-script - 如何使用谷歌应用脚本编辑器过滤列中的数据