PHP code example of inpin / lara-like

1. Go to this page and download the library: Download inpin/lara-like 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/ */

    

inpin / lara-like example snippets


'providers' => [
    \Inpin\LaraLike\LaraLikeServiceProvider::class,
],

class Book extends \Illuminate\Database\Eloquent\Model {
    use Inpin\LaraLike\Likeable;
}

$book->like(); // like the book for current user
$book->like($user); // pass in your own user
$book->like(0); // just add likes to the count, and don't track by user
$book->like('api'); // like the book for current user with guard 'api'
$book->like(null, 'bookmark') // add book for current user to bookmarks
$book->like($user, 'bookmark') // pass user and type

$book->unlike(); // remove like from the book
$book->unlike($user); // pass in your own user id
$book->unlike(0); // remove likes from the count -- does not check for user
$book->unlike('api'); // remove like from book for current user with guard 'api'
$book->unlike(null, 'bookmark') // remove current book from current user bookmarks
$book->unlike($user, 'bookmark') // pass user and type

$book->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes 
$book->likes()->where('type', 'bookmark')

$book->liked(); // check if currently logged in user liked the book
$book->liked($myUserId);

$book->likeCount($type); // determine number of likes for given $type (default type is 'like')

Article::whereLikedBy($myUserId) // find only books where user liked them
	->with('likeCounter') // highly suggested to allow eager load
	->get();
bash
php artisan vendor:publish --provider="Inpin\LaraLike\LaraLikeServiceProvider" --tag=migrations
php artisan migrate