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
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search
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
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
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit