Likable Helper for Eloquent models
Installation
Run composer require miragepresent/likeable;, (*1)
And php artisan migrate, (*2)
Usage
Just use Likeable trait in your model:, (*3)
namespace App;
use Illuminate\Database\Eloquent\Model;
use MiragePresent\Likeable\Likeable;
class Photo extends Model {
use Likeable;
}
Now You are able to use methods like(), dislike() and toggleLike() in your model for adding/removing a like of an
authorized user., (*4)
Example:, (*5)
/** @var \App\Photo $photo */
$photo = Photo::find(1);
// Add like to the photo
$photo->like();
var_dump($photo->is_liked); \\ true, 1
echo $photo->count_likes. ' user(s) liked this photo';
echo $photo->likedBy->ipmlode('name', ',') . ' liked this photo';