Skip to content

Commit

Permalink
Merge pull request #108 from kainxspirits/master
Browse files Browse the repository at this point in the history
Send events after database changes.
  • Loading branch information
hootlex authored Jul 3, 2018
2 parents 7dd74fb + cdfce9b commit 0100718
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/Traits/Friendable.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public function befriend(Model $recipient)
*/
public function unfriend(Model $recipient)
{
$deleted = $this->findFriendship($recipient)->delete();

Event::fire('friendships.cancelled', [$this, $recipient]);

return $this->findFriendship($recipient)->delete();
return $deleted;
}

/**
Expand Down Expand Up @@ -87,11 +89,13 @@ public function isFriendWith(Model $recipient)
*/
public function acceptFriendRequest(Model $recipient)
{
Event::fire('friendships.accepted', [$this, $recipient]);

return $this->findFriendship($recipient)->whereRecipient($this)->update([
$updated = $this->findFriendship($recipient)->whereRecipient($this)->update([
'status' => Status::ACCEPTED,
]);

Event::fire('friendships.accepted', [$this, $recipient]);

return $updated;
}

/**
Expand All @@ -101,11 +105,13 @@ public function acceptFriendRequest(Model $recipient)
*/
public function denyFriendRequest(Model $recipient)
{
Event::fire('friendships.denied', [$this, $recipient]);

return $this->findFriendship($recipient)->whereRecipient($this)->update([
$updated = $this->findFriendship($recipient)->whereRecipient($this)->update([
'status' => Status::DENIED,
]);

Event::fire('friendships.denied', [$this, $recipient]);

return $updated;
}


Expand Down Expand Up @@ -183,9 +189,11 @@ public function blockFriend(Model $recipient)
'status' => Status::BLOCKED,
]);

$this->friends()->save($friendship);

Event::fire('friendships.blocked', [$this, $recipient]);

return $this->friends()->save($friendship);
return $friendship;
}

/**
Expand All @@ -195,9 +203,11 @@ public function blockFriend(Model $recipient)
*/
public function unblockFriend(Model $recipient)
{
$deleted = $this->findFriendship($recipient)->whereSender($this)->delete();

Event::fire('friendships.unblocked', [$this, $recipient]);

return $this->findFriendship($recipient)->whereSender($this)->delete();
return $deleted;
}

/**
Expand Down

0 comments on commit 0100718

Please sign in to comment.