Today, I had spent 3 hours to fix one problem, the old program have a bug, originally, when a user profiles don ' t now allow Multi Logon, It would update the other login records of [loginaudit] table of this user,
But the code had a problem, it may not get his final login record correctly, and would update all his login record Includi Ng the final one.
Interestingly, I find out a method which Laravel provide, but never used before, Mass Update on one line of code. Can You image how easy it is.
$audit = \app\loginaudit::where (' Traineruserid ', $username)
->orderby (' id_num ',' DESC ')->firstorfail ();
Session::p ut (' id_login ', $audit->id_num);
Kick out other login session of same user
if ' N ')
{
$audit = \app\loginaudit::where (' Traineruserid ', $username)
->where ('id_num '<>', session (' Id_login '))
->whereraw (' logoutdatetime is NULL ')->update ([' Logoutdatetime '=>carbon::now ()]);
}
How to does a mass update in LARAVEL5 (inside Laravel 5 do a lot of data updates)