### Examples of Interaction Method Parameter Usage (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet provides various examples of how to call interaction methods like `follow` using different types of `$targets` parameters. It demonstrates passing single IDs, arrays of IDs, single Eloquent models, and collections of Eloquent models, along with specifying the target class. ```PHP // id / int|array $user->follow(1); // targets: 1, $class = App\User $user->follow(1, App\Post::class); // targets: 1, $class = App\Post $user->follow([1, 2, 3]); // targets: [1, 2, 3], $class = App\User // Model $post = App\Post::find(7); $user->follow($post); // targets: $post->id, $class = App\Post // Model array $posts = App\Post::popular()->get(); $user->follow($posts); // targets: [1, 2, ...], $class = App\Post ``` -------------------------------- ### Installing Laravel Acquaintances via Composer (Shell) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This command installs the Laravel Acquaintances package using Composer, a dependency manager for PHP. It's the first step to integrate the package into a Laravel project. ```sh composer require multicaret/laravel-acquaintances ``` -------------------------------- ### Working with InteractionRelation Model (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates how to directly interact with the `InteractionRelation` model to retrieve popular objects. It shows examples of fetching popular items across all types, for specific subject types (e.g., `App\Post`, `App\User`), and applying pagination to the results. ```PHP use Multicaret\Acquaintances\Models\InteractionRelation; // Get most popular object // 1- All types $relations = InteractionRelation::popular()->get(); // 2- subject_type = App\Post $relations = InteractionRelation::popular(App\Post::class)->get(); // 3- subject_type = App\User $relations = InteractionRelation::popular('user')->get(); // 4- subject_type = App\Post $relations = InteractionRelation::popular('post')->get(); // 5- Pagination $relations = InteractionRelation::popular(App\Post::class)->paginate(15); ``` -------------------------------- ### Getting Denied Friendships in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet fetches a list of denied friendships for a user. It supports optional pagination and selection of specific fields. ```php $user->getDeniedFriendships(); $user->getDeniedFriendships($perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Getting Pending Friend Requests in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet retrieves a list of pending friend requests for the user. ```php $user->getFriendRequests(); ``` -------------------------------- ### Managing Subscribers with CanBeSubscribed Trait (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates how an object, utilizing the `CanBeSubscribed` trait, can manage its subscribers. It provides methods to retrieve a list of subscribers, check if a specific user has subscribed, and get the total count of subscribers, including a human-readable format. ```PHP $object->subscribers(); // or $object->subscribers $object->isSubscribedBy($user); $object->subscribersCount(); // or as attribute $object->subscribers_count $object->subscribersCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Managing User Following in Laravel with CanFollow Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how to use the `CanFollow` trait to manage user following relationships. It includes methods for following, unfollowing, toggling follow status, retrieving followings, and checking if a user is following a target. It also shows how to get following counts. ```PHP $user->follow($targets); $user->unfollow($targets); $user->toggleFollow($targets); $user->followings()->get(); // App\User:class $user->followings(App\Post::class)->get(); $user->isFollowing($target); $object->followingCount(); // or as attribute $object->following_count $object->followingCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Managing Viewers with CanBeViewed Trait (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how an object, using the `CanBeViewed` trait, can manage its viewers. It provides methods to retrieve a list of viewers, check if a specific user has viewed the object, and get the total count of viewers, including a human-readable format. ```PHP $object->viewers()->get(); $object->isViewedBy($user); $object->viewersCount(); // or as attribute $object->viewers_count $object->viewersCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Getting Friend Count in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet returns the total number of friends for the user. ```php $user->getFriendsCount(); ``` -------------------------------- ### Getting Pending Request Count in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet returns the total number of pending friend requests for the user. ```php $user->getPendingsCount(); ``` -------------------------------- ### Getting All Blocked Friendships in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet retrieves a list of all blocked friendships for a user. It supports optional pagination and selection of specific fields. ```php $user->getBlockedFriendships(); $user->getBlockedFriendships($perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Getting Accepted Friendships in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet retrieves a list of accepted friendships for a user. It allows optional filtering by group name, pagination, and selection of specific fields. ```php $user->getAcceptedFriendships(); $user->getAcceptedFriendships($group_name, $perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Getting All Friendships in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet retrieves a list of all friendships for a user. It can be optionally filtered by a group name and paginated, allowing specification of desired fields. ```php $user->getAllFriendships(); $user->getAllFriendships($group_name, $perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Getting Pending Friendships in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet fetches a list of pending friendships for a user. It supports optional filtering by group name, pagination, and selection of specific fields. ```php $user->getPendingFriendships(); $user->getPendingFriendships($group_name, $perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Managing Object Reports Received in Laravel with CanBeReported Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates the `CanBeReported` trait, used for models that can be reported. It provides methods to retrieve reporters, check if an object is reported by a specific user, and get the total number of reporters in both raw and human-readable formats. ```PHP $object->reporters()->get(); // or $object->reporters $object->isReportedBy($user); $object->reportersCount(); // or as attribute $object->reporters_count $object->reportersCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Managing Object Likes Received in Laravel with CanBeLiked Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates the `CanBeLiked` trait, used for models that can receive likes. It provides methods to retrieve likers (or fans), check if an object is liked by a specific user, and get the total number of likers in both raw and human-readable formats. ```PHP $object->likers()->get(); $object->fans()->get(); // or $object->fans. it's an alias of likers() $object->isLikedBy($user); $object->likersCount(); // or as attribute $object->likers_count $object->likersCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Managing Follower Relationships in Laravel with CanBeFollowed Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates the use of the `CanBeFollowed` trait for models that can be followed. It provides methods to retrieve followers, check if an object is followed by a specific user, and get the total number of followers in both raw and human-readable formats. ```PHP $object->followers()->get(); $object->isFollowedBy($user); $object->followersCount(); // or as attribute $object->followers_count $object->followersCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Getting Blocked Friendships by Current User in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet fetches a list of friendships blocked by the current user. It supports optional pagination and selection of specific fields. ```php $user->getBlockedFriendshipsByCurrentUser(); $user->getBlockedFriendshipsByCurrentUser($perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Managing Object Favorites Received in Laravel with CanBeFavorited Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates the `CanBeFavorited` trait, used for models that can be favorited. It provides methods to retrieve favoriters, check if an object is favorited by a specific user, and get the total number of favoriters in both raw and human-readable formats. ```PHP $object->favoriters()->get(); // or $object->favoriters $object->isFavoritedBy($user); $object->favoritersCount(); // or as attribute $object->favoriters_count $object->favoritersCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Getting Friend Count in Specific Group in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This method returns the total number of friends within a specified group for the user. ```php $user->getFriendsCount($group_name); ``` -------------------------------- ### Getting Blocked Friendships by Other Users in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet retrieves a list of friendships where the current user has been blocked by others. It supports optional pagination and selection of specific fields. ```php $user->getBlockedFriendshipsByOtherUsers(); $user->getBlockedFriendshipsByOtherUsers($perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Getting Mutual Friend Count in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet returns the number of mutual friends between the current user and another specified user. ```php $user->getMutualFriendsCount($otherUser); ``` -------------------------------- ### Managing Voters with CanBeVoted Trait (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how an object, using the `CanBeVoted` trait, can manage its voters. It provides methods to retrieve lists of general voters, upvoters, and downvoters, check vote status by a specific user, and get counts for each vote type, including human-readable formats. ```PHP $object->voters()->get(); $object->isVotedBy($user); $object->votersCount(); // or as attribute $object->voters_count $object->votersCountReadable(); // return readable number with precision, i.e: 5.2K $object->upvoters()->get(); $object->isUpvotedBy($user); $object->upvotersCount(); // or as attribute $object->upvoters_count $object->upvotersCountReadable(); // return readable number with precision, i.e: 5.2K $object->downvoters()->get(); $object->isDownvotedBy($user); $object->downvotersCount(); // or as attribute $object->downvoters_count $object->downvotersCountReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Running Laravel Acquaintances Database Migrations (Shell) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This Artisan command executes the database migrations published by the Laravel Acquaintances package, creating the necessary tables in the database to support friendship and interaction functionalities. ```sh php artisan migrate ``` -------------------------------- ### Publishing Laravel Acquaintances Config and Migrations (Shell) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This Artisan command publishes the configuration file (`config/acquaintances.php`) and database migration files for the Laravel Acquaintances package. This step is crucial for customizing package settings and preparing the database tables. ```sh php artisan vendor:publish --provider="Multicaret\Acquaintances\AcquaintancesServiceProvider" ``` -------------------------------- ### Understanding Interaction Method Parameters (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet defines the common method signature for interaction methods like `follow`, `like`, `unfollow`, and `unlike`. It shows that these methods accept a `$targets` parameter, which can be an integer, an array of integers, or an Eloquent model, and an optional `$class` parameter to specify the target model type. ```PHP follow(array|int|\Illuminate\Database\Eloquent\Model $targets, $class = __CLASS__) ``` -------------------------------- ### Querying Acquaintances Relationships (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how to query relationships established by the Acquaintances package. It shows accessing relationships as dynamic properties or calling them as methods to apply additional Eloquent query constraints like `where`, `orderByDesc`, and `paginate`. ```PHP $followers = $user->followers; $followers = $user->followers()->where('id', '>', 10)->get(); $followers = $user->followers()->orderByDesc('id')->get(); $followers = $user->followers()->paginate(10); ``` -------------------------------- ### Configuring Friend Groups in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet shows how friend groups are defined in the `config/acquaintances.php` file. Groups are specified with a slug and a key, allowing customization of default groups or addition of new ones. ```php // config/acquaintances.php //... 'groups' => [ 'acquaintances' => 0, 'close_friends' => 1, 'family' => 2 ]; ``` -------------------------------- ### Setting Up an Eloquent Model with Acquaintances Traits (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This PHP snippet shows how to integrate the Laravel Acquaintances package into an Eloquent `User` model by using various traits like `Friendable`, `CanFollow`, `CanBeFollowed`, `CanLike`, `CanBeLiked`, `CanRate`, and `CanBeRated`. These traits provide the model with the ability to manage friendships and different types of social interactions. ```php use Multicaret\Acquaintances\Traits\Friendable; use Multicaret\Acquaintances\Traits\CanFollow; use Multicaret\Acquaintances\Traits\CanBeFollowed; use Multicaret\Acquaintances\Traits\CanLike; use Multicaret\Acquaintances\Traits\CanBeLiked; use Multicaret\Acquaintances\Traits\CanRate; use Multicaret\Acquaintances\Traits\CanBeRated; //... class User extends Model { use Friendable; use CanFollow, CanBeFollowed; use CanLike, CanBeLiked; use CanRate, CanBeRated; //... } ``` -------------------------------- ### Accepting a Friend Request (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet shows how a user (`$user`) can accept a pending friend request from a sender (`$sender`) using the `acceptFriendRequest` method. Upon acceptance, both users become friends. ```php $user->acceptFriendRequest($sender); ``` -------------------------------- ### Managing Friendships with Laravel Acquaintances (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates the core functionality of the Laravel Acquaintances package for managing friendships between two User models. It shows how to send a friend request, accept it, and subsequently unfriend a user, highlighting the `befriend`, `acceptFriendRequest`, and `unfriend` methods. ```php $user1 = User::find(1); $user2 = User::find(2); $user1->befriend($user2); $user2->acceptFriendRequest($user1); // The messy breakup :( $user2->unfriend($user1); ``` -------------------------------- ### Managing Object Liking in Laravel with CanLike Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates the `CanLike` trait, enabling models to like other objects. It includes methods for liking, unliking, toggling like status, checking if an object has been liked, and retrieving a list of liked objects, with an option to filter by specific model types. ```PHP $user->like($targets); $user->unlike($targets); $user->toggleLike($targets); $user->hasLiked($target); $user->likes()->get(); // default object: App\User:class $user->likes(App\Post::class)->get(); ``` -------------------------------- ### Managing Subscriptions with CanSubscribe Trait (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how a user model, utilizing the `CanSubscribe` trait, can manage subscriptions. It includes methods for subscribing, unsubscribing, toggling subscriptions, checking subscription status, and retrieving lists of subscribed targets, optionally filtered by a specific model class. ```PHP $user->subscribe($targets); $user->unsubscribe($targets); $user->toggleSubscribe($targets); $user->hasSubscribed($target); $user->subscriptions()->get(); // default object: App\User:class $user->subscriptions(App\Post::class)->get(); ``` -------------------------------- ### Managing Views with CanView Trait (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet illustrates how a user model, utilizing the `CanView` trait, can manage viewing interactions. It includes methods for marking targets as viewed, unviewed, toggling view status, checking if a target has been viewed, and retrieving lists of viewed items, optionally filtered by a specific model class. ```PHP $user->view($targets); $user->unview($targets); $user->toggleView($targets); $user->hasViewed($target); $user->viewers()->get(); // default object: App\User:class $user->viewers(App\Post::class)->get(); ``` -------------------------------- ### Managing Object Rating in Laravel with CanRate Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet shows how to use the `CanRate` trait for models that can rate other objects. It covers basic rating, unrating, toggling rate status, and retrieving ratings. It also demonstrates advanced usage for rating objects based on multiple factors (rate types) by setting the rate type before rating. ```PHP // Rate type in the following line will // be the same as the one specified // in config('acquaintances.rating.defaults.type') // if your app is using a single type of rating on your model, // like one factor only, then simply use the rate() as it's shown here, // and if you have multiple factors then // take a look the examples exactly below this these ones. $user->rate($targets); $user->unrate($targets); $user->toggleRate($targets); $user->ratings()->get(); // App\User:class $user->ratings(App\Post::class)->get(); $user->hasRated($target); // Some Examples on how to rate the object based on different factors (rating type) $user->setRateType('bedside-manners')->rate($target, 4); $user->setRateType('waiting-time')->rate($target, 3); $user->setRateType('quality')->rate($target, 4); $user->setRateType('delivery-time')->rate($target, 2); $user->setRateType('communication')->rate($target, 5); // Remember that you can always use the functions on $target which have this phrase "AllTypes" in them. check the below section for more details ``` -------------------------------- ### Sending a Friend Request (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This code demonstrates how to send a friend request from one user (`$user`) to another (`$recipient`) using the `befriend` method provided by the `Friendable` trait. The recipient will then have a pending friend request. ```php $user->befriend($recipient); ``` -------------------------------- ### Unblocking a Model (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how a user (`$user`) can unblock a previously blocked model (`$friend`) using the `unblockFriend` method, allowing for potential future interactions or friendship requests. ```php $user->unblockFriend($friend); ``` -------------------------------- ### Adding Interaction Traits to Target Model in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how to add `CanBeXXX` traits to target models like 'Post' or 'Book'. These traits enable the model to be liked, favorited, voted on, or rated by users. ```php use Multicaret\Acquaintances\Traits\CanBeLiked; use Multicaret\Acquaintances\Traits\CanBeFavorited; use Multicaret\Acquaintances\Traits\CanBeVoted; use Multicaret\Acquaintances\Traits\CanBeRated; class Post extends Model { use CanBeLiked, CanBeFavorited, CanBeVoted, CanBeRated; } ``` -------------------------------- ### Adding Interaction Traits to User Model in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how to add various `CanXXX` traits to the User model. These traits enable the user to perform actions like following, liking, favoriting, subscribing, and voting on other models. ```php use Multicaret\Acquaintances\Traits\CanFollow; use Multicaret\Acquaintances\Traits\CanLike; use Multicaret\Acquaintances\Traits\CanFavorite; use Multicaret\Acquaintances\Traits\CanSubscribe; use Multicaret\Acquaintances\Traits\CanVote; class User extends Model { use CanFollow, CanLike, CanFavorite, CanSubscribe, CanVote; } ``` -------------------------------- ### Managing Object Favoriting in Laravel with CanFavorite Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates the `CanFavorite` trait, enabling models to favorite other objects. It includes methods for favoriting, unfavoriting, toggling favorite status, checking if an object has been favorited, and retrieving a list of favorited objects, with an option to filter by specific model types. ```PHP $user->favorite($targets); $user->unfavorite($targets); $user->toggleFavorite($targets); $user->hasFavorited($target); $user->favorites()->get(); // App\User:class $user->favorites(App\Post::class)->get(); ``` -------------------------------- ### Managing Object Reporting in Laravel with CanReport Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates the `CanReport` trait, enabling models to report other objects. It includes methods for reporting, unreporting, toggling report status, checking if an object has been reported, and retrieving a list of reported objects, with an option to filter by specific model types. ```PHP $user->report($targets); $user->unreport($targets); $user->toggleReport($targets); $user->hasReported($target); $user->reports()->get(); // App\User:class $user->reports(App\Post::class)->get(); ``` -------------------------------- ### Adding Friendable Trait to User Model (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how to make an Eloquent `User` model 'friendable' by including the `Friendable` trait. This trait enables the model to send, accept, deny, and manage friend requests. ```php use Multicaret\Acquaintances\Traits\Friendable; class User extends Model { use Friendable; } ``` -------------------------------- ### Blocking a Model (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This code shows how a user (`$user`) can block another model (`$friend`) using the `blockFriend` method. Blocking prevents further interactions and friendship requests from the blocked model. ```php $user->blockFriend($friend); ``` -------------------------------- ### Denying a Friend Request (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This code illustrates how a user (`$user`) can deny a pending friend request from a sender (`$sender`) using the `denyFriendRequest` method. This action rejects the request without establishing a friendship. ```php $user->denyFriendRequest($sender); ``` -------------------------------- ### Grouping a Friend in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This method assigns a friend to a specific group using the provided friend model and group name. This allows for categorization of friendships. ```php $user->groupFriend($friend, $group_name); ``` -------------------------------- ### Retrieving Friends of Friends in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This method retrieves a collection of friends of friends. It supports optional pagination and selection of specific fields. ```php $user->getFriendsOfFriends(); // or $user->getFriendsOfFriends($perPage = 20); // or $user->getFriendsOfFriends($perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Retrieving Friends Collection in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This method retrieves a collection of friend models. It supports pagination, filtering by a specific group, and selecting desired fields, including cursor-based pagination. ```php $user->getFriends(); // or paginated $user->getFriends($perPage = 20, $group_name); // or paginated with certain fields $user->getFriends($perPage = 20, $group_name, $fields = ['id','name']); // or paginated with cursor & certain fields $user->getFriends($perPage = 20, $group_name, $fields = ['id','name'], $cursor = true); ``` -------------------------------- ### Managing Votes with CanVote Trait (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet shows how a user model, using the `CanVote` trait, can interact with voting functionalities. It includes methods for casting a general vote (defaulting to upvote), explicit upvoting and downvoting, canceling a vote, checking upvote/downvote status, and retrieving lists of voted items, optionally filtered by class. ```PHP $user->vote($target); // Vote with 'upvote' for default $user->upvote($target); $user->downvote($target); $user->cancelVote($target); $user->hasUpvoted($target); $user->hasDownvoted($target); $user->votes(App\Post::class)->get(); $user->upvotes(App\Post::class)->get(); $user->downvotes(App\Post::class)->get(); ``` -------------------------------- ### Checking for Pending Incoming Friend Requests (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet verifies if `$user` has a pending friend request originating from `$sender` using the `hasFriendRequestFrom` method. It returns `true` if a request is pending, `false` otherwise. ```php $user->hasFriendRequestFrom($sender); ``` -------------------------------- ### Checking for Pending Outgoing Friend Requests (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This code checks if `$user` has already sent a friend request to `$recipient` that is still pending, using the `hasSentFriendRequestTo` method. It returns `true` if an outgoing request exists. ```php $user->hasSentFriendRequestTo($recipient); ``` -------------------------------- ### Removing a Friend (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how to remove an existing friendship between two users. The `$user` calls the `unfriend` method on the `$friend` model to terminate their friendship. ```php $user->unfriend($friend); ``` -------------------------------- ### Filtering Friendships by Group Slug in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet demonstrates how to filter various friendship lists by passing a group slug. This allows retrieving friendships specific to a defined group, such as accepted or pending friendships. ```php $user->getAllFriendships($group_name); $user->getAcceptedFriendships($group_name); $user->getPendingFriendships($group_name); ... ``` -------------------------------- ### Managing Object Ratings Received in Laravel with CanBeRated Trait Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet details the `CanBeRated` trait, used for models that can receive ratings. It provides methods to retrieve raters, check if an object is rated by a user, and calculate various rating statistics like average, sum, and percentage, both for specific types and across all types. It also includes user-specific rating aggregates. ```PHP $object->raters()->get(); $object->isRatedBy($user); $object->averageRating(); // or as attribute $object->average_rating $object->averageRatingAllTypes(); // or as attribute $object->average_rating_all_types $object->sumRating(); // or as attribute $object->sum_rating $object->sumRatingAllTypes(); // or as attribute $object->sum_rating_all_types_all_types $object->sumRatingReadable(); // return readable number with precision, i.e: 5.2K $object->sumRatingAllTypesReadable(); // return readable number with precision, i.e: 5.2K $object->ratingPercent($max = 5); // calculating the percentage based on the passed coefficient $object->ratingPercentAllTypes($max = 5); // calculating the percentage based on the passed coefficient // User Related: $object->userAverageRatingAllTypes(); // or as attribute $object->user_average_rating_all_types $object->userSumRatingAllTypes(); // or as attribute $object->user_sum_rating_all_types $object->userSumRatingReadable(); // return readable number with precision, i.e: 5.2K $object->userSumRatingAllTypesReadable(); // return readable number with precision, i.e: 5.2K ``` -------------------------------- ### Retrieving a Single Friendship Record (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet retrieves a specific friendship record between `$user` and `$friend` using the `getFriendship` method. It returns the friendship model instance if it exists, allowing access to its properties. ```php $user->getFriendship($friend); ``` -------------------------------- ### Checking if a Model Is Blocked By Another (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This code checks if `$user` is currently blocked by `$friend` using the `isBlockedBy` method. It returns `true` if the `$user` is blocked by `$friend`, `false` otherwise. ```php $user->isBlockedBy($friend); ``` -------------------------------- ### Checking if a Model Has Blocked Another (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This snippet determines if `$user` has blocked `$friend` using the `hasBlocked` method. It returns `true` if the block relationship exists, `false` otherwise. ```php $user->hasBlocked($friend); ``` -------------------------------- ### Retrieving Mutual Friends Collection in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This method retrieves a collection of mutual friends with another specified user. It supports optional pagination and selection of specific fields. ```php $user->getMutualFriends($otherUser); // or $user->getMutualFriends($otherUser, $perPage = 20); // or $user->getMutualFriends($otherUser, $perPage = 20, $fields = ['id','name']); ``` -------------------------------- ### Checking Friendship Status Between Models (PHP) Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This code checks if `$user` is currently friends with `$friend` using the `isFriendWith` method. It returns a boolean value indicating the friendship status. ```php $user->isFriendWith($friend); ``` -------------------------------- ### Ungrouping a Friend from a Specific Group in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This method removes a friend from a specified group, such as the 'family' group. It requires the friend model and the group name. ```php $user->ungroupFriend($friend, 'family'); ``` -------------------------------- ### Ungrouping a Friend from All Groups in Laravel PHP Source: https://github.com/multicaret/laravel-acquaintances/blob/master/README.md This method removes a friend from all assigned groups. When called without a group name, it clears all group associations for the specified friend. ```php $user->ungroupFriend($friend); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.