1. Go to this page and download the library: Download namest/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/ */
class User extends Model
{
use \Namest\Likeable\LikerTrait;
// ...
}
class Post extends Model
{
use \Namest\Likeable\LikeableTrait;
// ...
}
$user = \App\User::find(1);
$post = \App\Post::find(2);
$like = $user->like($post); // Return Namest\Likeable\Like instance
$result = $user->unlike($post); // Return true when success and false on otherwise
$user = $like->liker; // Return model that like another model
$post = $like->likeable; // Return model that was liked by another model
$posts = $user->likes; // Return likeable collection that liker was liked
$users = $post->likers; // Return liker collection who like that post
$users = User::wasLike($post)->...->get(); // Return liker collection who like that post
$posts = Post::likedBy($user)->...->get(); // Return post collection which was liked by the user
\Event::listen('namest.likeable.liking', function ($liker, $likeable) {
// Do something
});
\Event::listen('namest.likeable.liked', function ($liker, $likeable, $like) {
// Do something
});
\Event::listen('namest.likeable.unliking', function ($liker, $likeable) {
// Do something
});
\Event::listen('namest.likeable.unliked', function ($liker, $likeable) {
// Do something
});