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

            

                }

 

how to do a mass update in Laravel5 ( 在Laravel 5里面怎么做大量数据更新 )的更多相关文章

  1. How to: Change Sales Rep/Team via Mass Update

    /* from: https://netsuite.custhelp.com/app/answers/detail/a_id/30057/kw/reassign%20sales */ How to c ...

  2. 09 Zabbix4.0系统clone、mass update使用

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 09 Zabbix4.0系统clone.mass update使用 1. clone使用: clo ...

  3. laravel5.3的多用户登录,经过验证laravel5.4可用【转帖】

    简介 在底层代码中,Laravel 的认证组件由 guards 和 providers组成,Guard 定义了用户在每个请求中如何实现认证,例如,Laravel 通过 session guard来维护 ...

  4. 后勤模块数据源的增量队列(Delta-Queue)三种更新模式(Update Mode)

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  5. mysql update case when和where之间的注意事项

    在日常开发中由于业务逻辑较为复杂,常常需要用到UPDATE和CASE...WHEN...THEN...ELSE...END一起做一些复杂的更新.有时候因为对这几个字句理解得不透彻会带来很大的困扰.因此 ...

  6. SqlDataAdapter.Update批量数据更新

    SqlDataAdapter.Update批量数据更新 使用SqlDataAdapter.Update可以方便地对数据库进行快速.批量数据更新.我们最常用的多条数据更新方法是使用循环多次执行SQL语句 ...

  7. Laravel5 学习与使用(一)

    2015-07-04 (1)  安装Laravel框架 ① 安装前的准备工作 使用Apache24 + PHP 5.6 + MySQL 开发环境完成PHP网站开发,所以Laravel的安装是建立在以上 ...

  8. 一张图带你看懂SpriteKit中Update Loop究竟做了神马!

    1首先Scene中只有开始一点时间用来回调其中的update方法 ;] 2然后是Scene中所有动作的模拟 3接下来是上一步完成之后,给你一个机会执行一些代码 4然后是Scene模拟其中的物理世界 5 ...

  9. select for update引发死锁分析

    本文针对MySQL InnoDB中在Repeatable Read的隔离级别下使用select for update可能引发的死锁问题进行分析. 1. 业务案例 业务中需要对各种类型的实体进行编号,例 ...

随机推荐

  1. Ubuntu 16.04安装7zip的图形界面工具PeaZip

    其实PeaZip不是7zip的图形界面工具,而是一整套方案,里面包括了7z格式的解压缩等. PeaZip Linux版本只有32位包,如果你使用的是64位Ubuntu系统,那么先打开终端运行下面的命令 ...

  2. storm ——Understanding the Parallelism of a Storm Topology

    http://www.michael-noll.com/blog/2012/10/16/understanding-the-parallelism-of-a-storm-topology/ 这篇文章好 ...

  3. gcc 5.2.0 编译安装笔记-20151110

    **转载请注明出处** by.haunying3 系统版本号 CentOS-6.6-x86_64-minimal 编译器 gcc-4.4.7通过yum安装 rpm -qa | grep gcc gcc ...

  4. node-npm/yarn

    很多人对npm或yarn了解甚少吧,下面我介绍一下常用的yarn/npm所谓的包管理工具. 首先我先介绍一下,npm属于国外Google镜像(下载贼慢),yarn属于Facebook开发的. npm: ...

  5. 异步FIFO的编程

    对于异步FIFO.最基本的两个方面是地址控制和空.满标志位的产生.首先地址控制分别为读地址和写地址,每次读写时能读写地址应该加1.计数次数为ram深度的2倍.当读写地址相等时则空标志位有效,当读写地址 ...

  6. karaf增加自己定义log4j的配置

    配置文件: karaf_home/etc/org.ops4j.pax.logging.cfg 增加配置: ### direct log messages to stdout ### log4j.app ...

  7. 2016/1/12 String 笔记整理

    String  简介                        文件名 Teststring 有实例 String类 即字符串类型,并不是Java的基本数据类型,但可以像基本数据类型一样使用,用双 ...

  8. mysql group by 组内排序 group by 原理

    mysql group by 组内排序   SELECT * FROM (SELECT MAX(id) AS t,wukong_uid, 1 AS tag FROM  toutiao_uid_gath ...

  9. js验证手机号,身份证,车牌号验证

    js验证手机号  <input type="text" class="identificationno"> // 身份证号码为15位或者18位,15 ...

  10. 【Unity3D】Unity3D SkinnedMeshRenderer换装系统

    转载请注明出处:http://www.cnblogs.com/shamoyuu/p/6505561.html 一.换装原理 游戏角色换装分为以下几步: 1.替换蒙皮网格 2.刷新骨骼 3.替换材质 上 ...