PHP code example of liquidstyle / laravel-likeable
1. Go to this page and download the library: Download liquidstyle/laravel-likeable 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/ */
liquidstyle / laravel-likeable example snippets
class Item extends \Illuminate\Database\Eloquent\Model {
use \Liquidstyle\Likeable\LikeableTrait;
use \Liquidstyle\Likeable\FavoriteableTrait;
use \Liquidstyle\Likeable\WishlistableTrait;
}
$item->like(); // like the item for current user
$item->like($myUserId); // pass in your own user id
$item->like(0); // just add likes to the count, and don't track by user
$item->unlike(); // remove like from the item
$item->unlike($myUserId); // pass in your own user id
$item->unlike(0); // remove likes from the count -- does not check for user
$item->likeCount; // get count of likes
$item->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes
$item->liked(); // check if currently logged in user liked the item
$item->liked($myUserId);
Item::whereLikedBy($myUserId) // find only items where user liked them
->with('likeCounter') // highly suggested to allow eager load
->get();
$item->favorite(); // favorite the item for current user
$item->favorite($myUserId); // pass in your own user id
$item->favorite(0); // just add favorites to the count, and don't track by user
$item->unfavorite(); // remove favorite from the item
$item->unfavorite($myUserId); // pass in your own user id
$item->unfavorite(0); // remove favorites from the count -- does not check for user
$item->favoriteCount; // get count of favorites
$item->favorites; // Iterable Illuminate\Database\Eloquent\Collection of existing favorites
$item->favorited(); // check if currently logged in user favorited the item
$item->favorited($myUserId);
Item::whereFavoritedBy($myUserId) // find only items where user favorited them
->with('favoriteCounter') // highly suggested to allow eager load
->get();
$item->wishlist(); // wishlist the item for current user
$item->wishlist($myUserId); // pass in your own user id
$item->wishlist(0); // just add wishlists to the count, and don't track by user
$item->unwishlist(); // remove wishlist from the item
$item->unwishlist($myUserId); // pass in your own user id
$item->unwishlist(0); // remove wishlists from the count -- does not check for user
$item->wishlistCount; // get count of wishlists
$item->wishlist; // Iterable Illuminate\Database\Eloquent\Collection of existing wishlists
$item->wishlisted(); // check if currently logged in user wishlisted the item
$item->wishlisted($myUserId);
Item::whereWishlistedBy($myUserId) // find only items where user wishlisted them
->with('wishlistCounter') // highly suggested to allow eager load
->get();