-
app/Providers/EventServiceProvider.php
Open in GitHub// Here's the file where all events and listeners get registered. // One of the listeners is default from Laravel, from Illuminate/Auth. use App\Events\UserApproved; use App\Events\UserVerified; use Illuminate\Auth\Events\Registered; use App\Listeners\SendNewUserNotification; use App\Listeners\SendUserApprovedNotification; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; class EventServiceProvider extends ServiceProvider { protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], UserVerified::class => [ SendNewUserNotification::class, ], UserApproved::class => [ SendUserApprovedNotification::class, ], ]; }
-
app/Events/UserVerified.php
Open in GitHubclass UserVerified { public $user; public function __construct(User $user) { $this->user = $user; } public function broadcastOn() { return new PrivateChannel('channel-name'); } }
-
app/Listeners/SendNewUserNotification.php
Open in GitHubclass SendNewUserNotification { public function handle(UserVerified $event) { $admins = Role::findByName('Super Admin')->users; Notification::send($admins, new ApproveUser($event->user)); } }