Esempio n. 1
0
 /**
  * Destroys a friendship (=destroys the user-to-user-relationship)
  * 
  * @param  int $id The ID if the user (friend)
  * @return Redirect
  */
 public function destroy($id)
 {
     $friend = User::findOrFail($id);
     $friendship = Friendship::areFriends(user()->id, $id)->firstOrFail();
     // It's important that users can only delete confirmed friendship to avoid abuse for friendship request spamming
     DB::table('friends')->whereSenderId($friendship->sender_id)->whereReceiverId($friendship->receiver_id)->whereConfirmed(true)->delete();
     $friend->sendSystemMessage(trans('friends::deletion_title'), trans('friends::deletion_text', [user()->username]));
     $this->alertFlash(trans('app.deleted', ['Friendship']));
     // Friendship terminated. Take this, diction!
     return Redirect::to('friends/' . user()->id);
 }
Esempio n. 2
0
 /**
  * Checks if the user is friend with another user or not.
  * 
  * @param  int      $friendID The user ID of the friend (=other user)
  * @return boolean
  */
 public function isFriendWith($friendID)
 {
     if (array_key_exists('friends', $this->getRelations())) {
         foreach ($this->friends as $friend) {
             if ($friend->id == $friendId) {
                 return true;
             }
         }
         return false;
     }
     $friendship = Friendship::areFriends($this->id, $friendID)->first();
     return $friendship !== null;
 }