PHP code example of gorankrgovic / laravel-likeable

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

    

gorankrgovic / laravel-likeable example snippets


use Gox\Contracts\Likeable\Liker\Models\Liker as LikerContract;
use Gox\Laravel\Likeable\Liker\Models\Traits\Liker;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements LikerContract
{
    use Liker;
}

use Gox\Contracts\Likeable\Likeable\Models\Likeable as LikeableContract;
use Gox\Laravel\Likeable\Likeable\Models\Traits\Likeable;
use Illuminate\Database\Eloquent\Model;

class Article extends Model implements LikeableContract
{
    use Likeable;
}

$user->like($article);

$article->likeBy(); // current user
$article->likeBy($user->id);

$user->unlike($article);

$article->unlikeBy(); // current user
$article->unlikeBy($user->id);

$article->likesCount;

$article->likesCounter;

$article->likes();

$article->likes;

$user->hasLiked($article);

$article->liked; // current user
$article->isLikedBy(); // current user
$article->isLikedBy($user->id);

$article->collectLikers();

$article->removeLikes();

Article::whereLikedBy($user->id)
    ->with('likesCounter') // Allow eager load (optional)
    ->get();

$sortedArticles = Article::orderByLikesCount()->get();
$sortedArticles = Article::orderByLikesCount('asc')->get();
sh
$ php artisan migrate