Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ddoddsr's avatar

Submit a job at login when Sanctum token is issued

I have a job that gets submitted via an observer (WORKING)

 {
     UserUpdatedJob::dispatch($user);
 }

The Observer is fired when the user model is saved (new, updated)

		protected $dispatchesEvents = [
        'saved' => UserObserver::class,
    ];

Now I want to dispatch the same or similar job at user login. This app is using Nova/Sanctum

0 likes
2 replies
rodrigo.pedra's avatar
Level 56

You can add a listener on your EventsServiceProvider that listens to this event: Illuminate\Auth\Events\Login

A listener to the exact same event to save the last login timestamp in one of my projects:

<?php

namespace App\Providers;

use App\Auth\Listeners\UpdateLoginInfoListener;
use Illuminate\Auth\Events\Login;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array<class-string, array<int, class-string>>
     */
    protected $listen = [
        Login::class => [UpdateLoginInfoListener::class],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
    }
}

If you are not familiar with event listener, please look the docs about it:

https://laravel.com/docs/8.x/events#defining-listeners

Please or to participate in this conversation.