PHP code example of multicaret / laravel-acquaintances
1. Go to this page and download the library: Download multicaret/laravel-acquaintances library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
multicaret / laravel-acquaintances example snippets
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;
//...
}
use Multicaret\Acquaintances\Traits\Friendable;
class User extends Model
{
use Friendable;
}
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;
}
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;
}
$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
// 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
$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
$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
$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
$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
$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();
$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
$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