Not sure how to listen for UserLevelledUp #70
-
Hey there 👋 I've tried listening for this event ( UserLevelledUp ) ( following multiple examples from the docs and a few of my own ), nothing seems to work. I've tested by seeing if it would log, and it doesn't do that either. Any ideas? Code snippets would be appreciated ❤️ Current code 👇 <?php
namespace App\Listeners;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use LevelUp\Experience\Events\UserLevelledUp;
class CelebrateUserLevelUp
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserLevelledUp $event
* @return void
*/
public function handle(UserLevelledUp $event)
{
// Log information
Log::info('CelebrateUserLevelUp listener: Event UserLevelledUp triggered', [
'time' => now(),
'level' => $event->level
]);
// Sending a notification
Notification::make()
->title('Level Up')
->icon('heroicon-c-arrow-trending-up')
->iconColor('success')
->body('You have reached level ' . $event->level . '! 🎉')
->send($event->user);
}
} Listener is automatically registered according to manual documentation. Running This is running Laravel 11 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi, It looks like you're doing it right, and the Laravel docs say it should auto-discover the events. I noticed the same thing too when I tried replicating this. I seem to have managed to get around it by adding this to Event::listen(
events: \LevelUp\Experience\Events\UserLevelledUp::class,
listener: \App\Listeners\CelebrateUserLevelUp::class,
); See if that works for you. |
Beta Was this translation helpful? Give feedback.
Hi,
It looks like you're doing it right, and the Laravel docs say it should auto-discover the events.
I noticed the same thing too when I tried replicating this.
I seem to have managed to get around it by adding this to
AppServiceProvider
See if that works for you.