Skip to content

Latest commit

 

History

History
61 lines (48 loc) · 1.07 KB

Events.md

File metadata and controls

61 lines (48 loc) · 1.07 KB

How to use events

for simplicity we will use events subscriber in this example

add the following in EventServiceProvider.php

protected $subscribe = [
    'App\Listeners\FriendshipsSubscriber',
];

then in FriendshipsSubscriber.php

class FriendshipsSubscriber implements ShouldQueue
{
  ...
  public function subscribe($events)
  {
      $events->listen(
          'friendrequest.sent',
          'App\Listeners\FriendshipsSubscriber@onFriendRequestSent'
      );

      $events->listen(
          'friendrequest.accepted',
          'App\Listeners\FriendshipsSubscriber@onFriendRequestAccepted'
      );

      $events->listen(
          'friendship.deleted',
          'App\Listeners\FriendshipsSubscriber@onFriendDeleted'
      );
  }
  ...
}

then add the following methods

...
public function onFriendRequestSent($sender, $recipient)
{
   ...
}

public function onFriendRequestAccepted($recipient, $sender)
{
    ...
}

public function onFriendDeleted($deleter, $deleted)
{
    ...
}
...