$ php artisan make:migration add_column_last_login_at_users_table –table=users
migration
public function up() { Schema::table('users', function (Blueprint $table) { // $table->timestamp('last_login_at')->nullable()->after('remember_token')->comment('最終ログイン'); }); }
$ php artisan migrate
app/Providers/EventServiceProvider.php
protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], 'App\Events\Logined' => [ 'App\Listeners\LastLoginListener', ], ];
$ php artisan event:generate
app/Listeners/LastLoginListener.php
public function handle(Logined $event) { $user = Auth::user(); $user->last_login_at = Carbon::now(); $user->save(); }
### test
use App\Events\Logined; public function testForm(){ event(new Logined()); return view('admin.test'); }
$ php artisan serve –host 192.168.33.10 –port 8000
http://192.168.33.10:8000/admin/test/form
mysql> select * from users;
問題は、このevent(new Logined());をどこで仕込むかやな。。。
Laravel8系だとLoginControllerがない。。。。
というか、もっと優先順位が高い事が入ったーーーーーーーーーーー