add login_at to User

This commit is contained in:
2020-04-12 09:42:13 +02:00
parent 0a535c165d
commit 24d27a68ac
4 changed files with 61 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Listeners;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Auth;
class UserLoginAttempt
{
/**
* Handle the event.
*
* @return void
*/
public function handle()
{
Auth::user()->update(['login_at' => now()]);
}
}

View File

@@ -19,7 +19,10 @@ class User extends Authenticatable
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'name',
'email',
'password',
'login_at',
];
/**

View File

@@ -2,6 +2,8 @@
namespace App\Providers;
use App\Events\UserLoggedIn;
use App\Listeners\UpdateUserMetaData;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
@@ -18,6 +20,9 @@ class EventServiceProvider extends ServiceProvider
Registered::class => [
SendEmailVerificationNotification::class,
],
\Illuminate\Auth\Events\Authenticated::class => [
'App\Listeners\UserLoginAttempt@handle'
],
];
/**

View File

@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddLoginAtToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->timestamp('login_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('login_at');
});
}
}