コード例 #1
0
ファイル: Friendship.php プロジェクト: joancefet/Contentify
 /**
  * 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);
     });
 }
コード例 #2
0
ファイル: Friendship.php プロジェクト: chirilo/Contentify
 /**
  * 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);
     });
 }