Laravel Likeable

rtconner/laravel-likeable image

Laravel Likeable stats

Downloads
297K
Stars
396
Open Issues
9
Forks
48

View on GitHub →

Trait for Laravel Eloquent models to allow easy implementation of a 'like' or 'favorite' or 'remember' feature.

Laravel Likeable Plugin

Trait for Laravel Eloquent models to allow easy implementation of a "like" or "favorite" or "remember" feature.

Composer Install

composer require rtconner/laravel-likeable

Then run the migrations

php artisan migrate

Setup your models

class Article extends \Illuminate\Database\Eloquent\Model {
use \Conner\Likeable\Likeable;
}

Sample Usage

$article->like(); // like the article for current user
$article->like($myUserId); // pass in your own user id
$article->like(0); // just add likes to the count, and don't track by user
 
$article->unlike(); // remove like from the article
$article->unlike($myUserId); // pass in your own user id
$article->unlike(0); // remove likes from the count -- does not check for user
 
$article->likeCount; // get count of likes
 
$article->likes; // Iterable Illuminate\Database\Eloquent\Collection of existing likes
 
$article->liked(); // check if currently logged in user liked the article
$article->liked($myUserId);
 
Article::whereLikedBy($myUserId) // find only articles where user liked them
->with('likeCounter') // highly suggested to allow eager load
->get();

Credits

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Rtconner Laravel Likeable Related Articles

Laravel Love: Likes and Dislikes for Eloquent Models image

Laravel Love: Likes and Dislikes for Eloquent Models

Read article
Honeybadger logo

Honeybadger

Simple developer-focused application monitoring for Laravel. Error tracking, log management, uptime monitoring, status pages, and more!

Honeybadger
LoadForge logo

LoadForge

Scalable load testing for web apps & APIs. Simulate real-world traffic and identify breaking points and performance limits with powerful, scalable load tests designed for Laravel.

LoadForge
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic