PHP code example of oroalej / laravel-likeable

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

    

oroalej / laravel-likeable example snippets


// Liker
use Illuminate\Foundation\Auth\User as Authenticatable;
use Oroalej\Likeable\Models\Traits\Liker;

Class User extends Authenticatable 
{
  use Liker;
}

// Likeable
use Illuminate\Database\Eloquent\Model;
use Oroalej\Likeable\Models\Traits\Likeable;

Class Post extends Model 
{
  use Likeable;
}

$user = User::find(1);
$post = Post::find(1);

// Liker
$user->like($post);
$user->unlike($post);

// Likeable
$post->isLikedBy($user);
$post->unlikedBy($user);

// Liker
$user = User::find(1);
$user->liked(Post::class);
$user->liked();

// Likeable
$post = Post::find(1);
$post->likers(User::class);
$post->likers()

// Liker
$user = User::find(1);
$user->getLikeCountByType(Post::class);
$user->getTotalLikeCount();

// Likeable
// To avoid the n+1 issue, please make sure to 
bash
php artisan migrate