To listen for an event, first you need to define a listener, then register it in EventServiceProvider
:
app/Providers/EventServiceProvider.php
protected $listen = [
'Hazzard\Comments\Events\CommentWasPosted' => [
'App\Listeners\HandleCommentWasNotification',
],
];
app/Listeners/HandleCommentWasNotification.php
<?php
namespace App\Listeners;
use Hazzard\Comments\Comments\Comment;
use Hazzard\Comments\Events\CommentWasPosted;
class HandleCommentWasNotification
{
/**
* Handle the event.
*
* @param CommentWasPosted $event
* @return void
*/
public function handle(CommentWasPosted $event)
{
// Access the comment using $event->comment...
}
}
You can find all of events in the src/Events
folder.