仅当侦听器 handle() 方法中的 last_login_at=null 时才更新 last_login_at 字段。
Update the last_login_at field only if last_login_at=null from the listener handle() method.
在我的 LogSuccessfulLogin 侦听器中,我正在更新 last_login_at 用户成功 login.but 现在我希望 last_login_at 仅在 last_login_at 为空或 empty.can 我是否使用以下代码来做到这一点?
if($event->user->where('last_login_at','NULL'))
{
$event->user->last_login_at = date('Y-m-d H:i:s');
$event->user->save();
}
LogSuccessfulLogin Listner
namespace App\Listeners;
use Illuminate\Auth\Events\Login;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class LogSuccessfulLogin
{
public function __construct()
{
//
}
public function handle(Login $event)
{
$event->user->last_login_at = date('Y-m-d H:i:s');
$event->user->save();
}
}
也许empty()
可以帮到你:
if (empty($event->user->last_login_at)) {
$event->user->last_login_at = date('Y-m-d H:i:s');
$event->user->save();
}
在我的 LogSuccessfulLogin 侦听器中,我正在更新 last_login_at 用户成功 login.but 现在我希望 last_login_at 仅在 last_login_at 为空或 empty.can 我是否使用以下代码来做到这一点?
if($event->user->where('last_login_at','NULL'))
{
$event->user->last_login_at = date('Y-m-d H:i:s');
$event->user->save();
}
LogSuccessfulLogin Listner
namespace App\Listeners;
use Illuminate\Auth\Events\Login;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class LogSuccessfulLogin
{
public function __construct()
{
//
}
public function handle(Login $event)
{
$event->user->last_login_at = date('Y-m-d H:i:s');
$event->user->save();
}
}
也许empty()
可以帮到你:
if (empty($event->user->last_login_at)) {
$event->user->last_login_at = date('Y-m-d H:i:s');
$event->user->save();
}