Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
merodiro committed May 9, 2017
1 parent 37e4a4f commit 9fe2217
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/Friendable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ public function addFriend($recipient)
$friendshipStatus = $this->checkFriendship($recipient);

if ($friendshipStatus == 'not friends') {

Event::fire('friendrequest.sent', [$this, $recipient]);

return Friendship::create([
'requester' => $this->id,
'user_requested' => $recipient->id,
]);
}

return 0;
}

public function checkFriendship($user)
Expand All @@ -34,11 +31,15 @@ public function checkFriendship($user)

if (!$friendship) {
return 'not friends';
} elseif ($friendship->status == 1) {
}

if ($friendship->status == 1) {
return 'friends';
} elseif ($friendship->requester == $this->id) {
}
if ($friendship->requester == $this->id) {
return 'waiting';
} elseif ($friendship->user_requested == $this->id) {
}
if ($friendship->user_requested == $this->id) {
return 'pending';
}
}
Expand Down Expand Up @@ -66,25 +67,40 @@ public function deleteFriend($user)

public function friends()
{
$recipients = Friendship::whereSender($this)->accepted(1)->pluck('user_requested')->all();
$senders = Friendship::whereRecipient($this)->accepted(1)->pluck('requester')->all();
$recipients = Friendship::whereSender($this)
->accepted(1)
->pluck('user_requested')
->all();
$senders = Friendship::whereRecipient($this)
->accepted(1)
->pluck('requester')
->all();

$friendsIds = array_merge($recipients, $senders);

return static::whereIn('id', $friendsIds)->get();
return static::whereIn('id', $friendsIds)
->get();
}

public function friendRequestFrom()
{
$senders = Friendship::whereRecipient($this)->accepted(0)->pluck('requester')->all();
$senders = Friendship::whereRecipient($this)
->accepted(0)
->pluck('requester')
->all();

return static::whereIn('id', $senders)->get();
return static::whereIn('id', $senders)
->get();
}

public function friendRequestTo()
{
$recipients = Friendship::whereSender($this)->accepted(0)->pluck('user_requested')->all();
$recipients = Friendship::whereSender($this)
->accepted(0)
->pluck('user_requested')
->all();

return static::whereIn('id', $recipients)->get();
return static::whereIn('id', $recipients)
->get();
}
}

0 comments on commit 9fe2217

Please sign in to comment.