Example #1
0
 /**
  * Query scope that returns only the friendships of two users
  * 
  * @param  Builder      $query       The query builder object
  * @param  int          $friendOneId The ID of the first user
  * @param  int          $friendTwoId The ID of the second user
  * @return Builder
  */
 public function scopeAreFriends($query, $friendOneId, $friendTwoId)
 {
     return $query->where(function ($query) use($friendOneId, $friendTwoId) {
         $query->whereSenderId($friendOneId)->whereReceiverId($friendTwoId);
     })->orWhere(function ($query) use($friendOneId, $friendTwoId) {
         $query->whereReceiverId($friendOneId)->whereSenderId($friendTwoId);
     });
 }
Example #2
0
 /**
  * Query scope that returns only the (confirmed) friendships of two users
  * 
  * @param  Builder      $query       The query builder object
  * @param  int          $friendOneId The ID of the first user
  * @param  int          $friendTwoId The ID of the second user
  * @param  boolean      $confirmed   Only show confirmed friendships? Default = true
  * @return Builder
  */
 public function scopeAreFriends($query, $friendOneId, $friendTwoId, $confirmed = true)
 {
     if ($confirmed) {
         $query->whereConfirmed(1);
     }
     return $query->where(function ($query) use($friendOneId, $friendTwoId) {
         $query->whereSenderId($friendOneId)->whereReceiverId($friendTwoId);
     })->orWhere(function ($query) use($friendOneId, $friendTwoId) {
         $query->whereReceiverId($friendOneId)->whereSenderId($friendTwoId);
     });
 }