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()]);

            

                }

 

最新文章

  1. Git本地提交到远程指定分支
  2. C#扩展特性
  3. android 开源库集合的链接列表
  4. ubunutu_install_sublime_china
  5. NHibernate 存储过程使用
  6. Quartz CronTrigger应用
  7. 【转】amCharts,一款值得推荐的Flash charts图组件
  8. mysq建立索引的优缺点
  9. Python json &amp; pickle, shelve 模块
  10. vim主题颜色
  11. cocos2dx-lua调用C++
  12. 关于MongoDB数据库的日志解析
  13. Custom partition assignment and migration kafka集群扩充迁移指定partition
  14. Java封装、继承整理
  15. 一个价格,两份大礼!Mockplus X MindManager限时联合大促
  16. Vue 旅游网首页开发1-工具安装及码云使用
  17. django之block extend标签
  18. 【自动化专题】selenium如何轻松搞定文件上传
  19. 洛谷P2017晕牛
  20. 一个web应用的诞生(5)--数据表单

热门文章

  1. Java函数式接口Function
  2. 绿盟NF防火墙系统
  3. mybatis bug之resultmap缺少object-relation匹配参数password,造成设置密码不成功
  4. android意图传參数(四)
  5. 【剑指Offer学习】【面试题65:滑动窗体的最大值】
  6. AES加密算法的C++实现
  7. android PercentRelativeLayout 支持百分比来设置控件的宽高
  8. [Qt总结篇]终端远程升级client
  9. C++求解数组中出现超1/4的三个数字。
  10. Echarts 如何使用 bmap 的 API