Events Flashcards
1
Q
Creating Event & Listener
A
php artisan make:event UserEvent
php artisan make:listener UserListener –event=UserEvent
2
Q
Register for event and listener
A
Go to App/providers/EventserviceProvider
don’‘t forget to input event&lister file
UserEvent::class =>[
UserListener::class,
]
3
Q
Call event
A
Route::get(‘/event’,function (){
$array=[“John”,”Henry”,”Philli”];
UserEvent::dispatch($array);
});
4
Q
Working from Listener file
A
in UserListener file public function handle(UserEvent $event) { foreach ($event->users as $user){ echo $user; }