@@ -148,7 +148,6 @@ public function groupFriend(Model $friend, $groupSlug)
148148 */
149149 public function ungroupFriend (Model $ friend , $ groupSlug = '' )
150150 {
151-
152151 $ friendship = $ this ->findFriendship ($ friend )->first ();
153152 $ groupsAvailable = config ('acquaintances.friendships_groups ' , []);
154153
@@ -361,10 +360,9 @@ public function getMutualFriendsCount($other)
361360 */
362361 public function getFriendsOfFriends ($ perPage = 0 , array $ fields = ['* ' ])
363362 {
364- return $ this ->getOrPaginate ($ this ->friendsOfFriendsQueryBuilder (), $ perPage , $ fields );
363+ return $ this ->getOrPaginate ($ this ->getFriendsOfFriendsQueryBuilder (), $ perPage , $ fields );
365364 }
366365
367-
368366 /**
369367 * Get the number of friends
370368 *
@@ -424,19 +422,28 @@ private function findFriendship(Model $recipient)
424422 *
425423 * @return \Illuminate\Database\Eloquent\Collection
426424 */
427- private function findFriendships ($ status = null , string $ groupSlug = '' , string $ type = 'all ' )
425+ public function findFriendships ($ status = null , string $ groupSlug = '' , string $ type = 'all ' )
428426 {
429427 $ friendshipModelName = Interaction::getFriendshipModelName ();
430428 $ query = $ friendshipModelName ::where (function ($ query ) use ($ type ) {
431429 switch ($ type ) {
432430 case 'all ' :
433- $ query ->where (function ($ q ) {$ q ->whereSender ($ this );})->orWhere (function ($ q ) {$ q ->whereRecipient ($ this );});
431+ $ query ->where (function ($ q ) {
432+ $ q ->whereSender ($ this );
433+ })
434+ ->orWhere (function ($ q ) {
435+ $ q ->whereRecipient ($ this );
436+ });
434437 break ;
435438 case 'sender ' :
436- $ query ->where (function ($ q ) {$ q ->whereSender ($ this );});
439+ $ query ->where (function ($ q ) {
440+ $ q ->whereSender ($ this );
441+ });
437442 break ;
438443 case 'recipient ' :
439- $ query ->where (function ($ q ) {$ q ->whereRecipient ($ this );});
444+ $ query ->where (function ($ q ) {
445+ $ q ->whereRecipient ($ this );
446+ });
440447 break ;
441448 }
442449 })->whereGroup ($ this , $ groupSlug );
@@ -456,22 +463,22 @@ private function findFriendships($status = null, string $groupSlug = '', string
456463 *
457464 * @return \Illuminate\Database\Eloquent\Builder
458465 */
459- private function getFriendsQueryBuilder ($ groupSlug = '' )
466+ public function getFriendsQueryBuilder ($ groupSlug = '' )
460467 {
461-
462468 $ friendships = $ this ->findFriendships (Status::ACCEPTED , $ groupSlug )->get (['sender_id ' , 'recipient_id ' ]);
463469 $ recipients = $ friendships ->pluck ('recipient_id ' )->all ();
464470 $ senders = $ friendships ->pluck ('sender_id ' )->all ();
465471
466- return $ this ->where ('id ' , '!= ' , $ this ->getKey ())->whereIn ('id ' , array_merge ($ recipients , $ senders ));
472+ return $ this ->where ('id ' , '!= ' , $ this ->getKey ())
473+ ->whereIn ('id ' , array_merge ($ recipients , $ senders ));
467474 }
468475
469476 /**
470477 * Get the query builder of the 'friend' model
471478 *
472479 * @return \Illuminate\Database\Eloquent\Builder
473480 */
474- private function getMutualFriendsQueryBuilder (Model $ other )
481+ public function getMutualFriendsQueryBuilder (Model $ other )
475482 {
476483 $ user1 ['friendships ' ] = $ this ->findFriendships (Status::ACCEPTED )->get (['sender_id ' , 'recipient_id ' ]);
477484 $ user1 ['recipients ' ] = $ user1 ['friendships ' ]->pluck ('recipient_id ' )->all ();
@@ -488,7 +495,8 @@ private function getMutualFriendsQueryBuilder(Model $other)
488495 )
489496 );
490497
491- return $ this ->whereNotIn ('id ' , [$ this ->getKey (), $ other ->getKey ()])->whereIn ('id ' , $ mutualFriendships );
498+ return $ this ->whereNotIn ('id ' , [$ this ->getKey (), $ other ->getKey ()])
499+ ->whereIn ('id ' , $ mutualFriendships );
492500 }
493501
494502 /**
@@ -498,7 +506,7 @@ private function getMutualFriendsQueryBuilder(Model $other)
498506 *
499507 * @return \Illuminate\Database\Eloquent\Builder
500508 */
501- private function friendsOfFriendsQueryBuilder ($ groupSlug = '' )
509+ public function getFriendsOfFriendsQueryBuilder ($ groupSlug = '' )
502510 {
503511 $ friendships = $ this ->findFriendships (Status::ACCEPTED )->get (['sender_id ' , 'recipient_id ' ]);
504512 $ recipients = $ friendships ->pluck ('recipient_id ' )->all ();
@@ -522,14 +530,6 @@ private function friendsOfFriendsQueryBuilder($groupSlug = '')
522530 array_merge ($ fofs ->pluck ('sender_id ' )->all (), $ fofs ->pluck ('recipient_id ' )->all ())
523531 );
524532
525- // Alternative way using collection helpers
526- // $fofIds = array_unique(
527- // $fofs->map(function ($item) {
528- // return [$item->sender_id, $item->recipient_id];
529- // })->flatten()->all()
530- // );
531-
532-
533533 return $ this ->whereIn ('id ' , $ fofIds )->whereNotIn ('id ' , $ friendIds );
534534 }
535535
0 commit comments