how to do a mass update in Laravel5 ( 在Laravel 5里面怎么做大量数据更新 )
2024-09-08 04:51:29
Today, I had spent 3 hours to fix one problem, The old program has a bug, originally, when a user profile don’t now allow Multi Logon, It will update the other login records of [LoginAudit] table of this user,
But the code has a problem, it may not get his final login record correctly, and will update all his login record including the final one.
Interestingly, I find out a method which Laravel provide, but never used before, Mass Update in One line of code. can you image how easy it is .
$audit = \App\LoginAudit::where('TrainerUserID', $username)
->orderBy('id_num','DESC')->firstOrFail();
Session::put('id_login', $audit->id_num);
//kick out other login session of same user
if($user->MultiLogonAllowed == 'N')
{
$audit= \App\LoginAudit::where('TrainerUserID', $username)
->where('id_num', '<>', session('id_login'))
->whereRaw(' LogoutDateTime IS NULL')->update(['LogoutDateTime'=>Carbon::now()]);
}
最新文章
- Git本地提交到远程指定分支
- C#扩展特性
- android 开源库集合的链接列表
- ubunutu_install_sublime_china
- NHibernate 存储过程使用
- Quartz CronTrigger应用
- 【转】amCharts,一款值得推荐的Flash charts图组件
- mysq建立索引的优缺点
- Python json &; pickle, shelve 模块
- vim主题颜色
- cocos2dx-lua调用C++
- 关于MongoDB数据库的日志解析
- Custom partition assignment and migration kafka集群扩充迁移指定partition
- Java封装、继承整理
- 一个价格,两份大礼!Mockplus X MindManager限时联合大促
- Vue 旅游网首页开发1-工具安装及码云使用
- django之block extend标签
- 【自动化专题】selenium如何轻松搞定文件上传
- 洛谷P2017晕牛
- 一个web应用的诞生(5)--数据表单