1. Go to this page and download the library: Download overtrue/laravel-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/ */
overtrue / laravel-like example snippets
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Overtrue\LaravelLike\Traits\Liker;
class User extends Authenticatable
{
use Liker;
<...>
}
use Illuminate\Database\Eloquent\Model;
use Overtrue\LaravelLike\Traits\Likeable;
class Post extends Model
{
use Likeable;
<...>
}
// all
$user->likes()->count();
// short way
$user->totalLikes;
// with type
$user->likes()->withType(Post::class)->count();
// likers count
$post->likers()->count();
// short way
$post->totalLikers