Laravel Markable is a package to Integrate likes, bookmarks, favorites, reactions, and custom-made marks into your application.
The basic usage is adding a
Markable trait and types of “marks” you want to allow for a given model. For example, if you have a
Course model and you want to let users like the course:
7class Course extends Model
9 use Markable;
11 protected $fillable = [
16 protected static $marks = [
With that model in place, here’s what it looks like to manage marks using this package:
4// marks the course liked for the given user
7// unmarks the course liked for the given user
10// toggles the course like for the given user
13// returns whether the given user likes a course or not
16// returns how many users like a course
Like model is built-in to the package, but you can also build custom mark models, such as
Pledge that allows a user to pledge a donation to a cause.
The package includes various mark types out-of-the-box, including:
On the other side of adding a Like for a user, you might what to list all likes for a given user so they can see what courses they’ve liked:
1// All course models with a like from the given user
6// All post models with a 'heart' reaction from the given user
You can learn more about this package, get full installation instructions, and view the source code on GitHub.