PHP code example of sebastian-kennedy / laravel-like

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

    

sebastian-kennedy / laravel-like example snippets




namespace SebastianKennedy\LaravelLike\Tests\Models;

use Illuminate\Database\Eloquent\Model;
use SebastianKennedy\LaravelLike\Behaviors\CanBeLikedBehavior;

class Book extends Model
{
    use CanBeLikedBehavior;

    protected $fillable = ['title'];
}



namespace SebastianKennedy\LaravelLike\Tests\Models;

use Illuminate\Database\Eloquent\Model;
use SebastianKennedy\LaravelLike\Behaviors\CanLikeBehavior;

class User extends Model
{
    use CanLikeBehavior;
    protected $fillable = ['name'];
}



$user = User::first();
$book = Book::first();

$user-like($book);
$user->unlike($book);
$user->toggleLike($book);
$user->hasLiked($book);
$user->likes();

$book->isLikedBy($user);
$book->likes();
$book->likers();