The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

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
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
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
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
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
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