我在上次登录时使用 Laravel 身份验证事件,但是当时间戳记到我在“LAST_LOGIN”列中的代码的每一行时出现问题我希望它只记录在登录用户中。但它看起来像登录时间将节省给每个用户。作为我附上的图片。
app\Listeners\UpdateLastSignInAt
<?php
namespace App\Listeners;
use Illuminate\Auth\Events\Login;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Carbon\Carbon;
class UpdateLastSignInAt
{
public function __construct()
{
//
}
public function handle(Login $event)
{
$event->user->LAST_LOGIN = Carbon::now();
$event->user->save();
}
}
\app\User.php --model--
<?php
namespace App;
use Laravel\Passport\HasApiTokens;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasApiTokens, Notifiable;
protected $table = 'SYSM_USERS';
public $timestamps = false;
protected $primaryKey = null;
public $incrementing = false;
protected $fillable = [
'ID', 'USER_NAME', 'PASSWORD', 'FIRST_NAME', 'LAST_NAME', 'DEPART_ID','E_MAIL','NOTE','STATUS','LAST_LOGIN','CREATED_BY','CREATED_DATE','UPDATED_BY','UPDATED_DATE'
];
protected $hidden = [
'PASSWORD', 'remember_token',
];
protected $dates = ['LAST_LOGIN','CREATED_DATE','UPDATED_DATE'];
public function getAuthPassword()
{
return $this->attributes['PASSWORD'];
}
}
\app\Providers\EventServiceProvider
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
喵喔喔
qq_花开花谢_0