Video
Description
This package allows you to easily add the markable feature to your application, as for example likes, bookmarks, favorites and so on.
To use the package, add the Maize\Markable\Markable trait to the model where you want to have marks.
Once done, you can define the list of possible marks for the given model implementing the $marks array with the list of mark classes' namespace.
Here's an example model including the Markable trait and implementing the Like mark:
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model;use Maize\Markable\Markable;use Maize\Markable\Models\Like; class Course extends Model{ use Markable; protected $fillable = [ 'title', 'description', ]; protected static $marks = [ Like::class, ];}
You can now assign likes to the model:
use App\Models\Course;use Maize\Markable\Models\Like; $course = Course::firstOrFail();$user = auth()->user(); Like::add($course, $user); // marks the course liked for the given user Like::remove($course, $user); // unmarks the course liked for the given user Like::toggle($course, $user); // toggles the course like for the given user Like::has($course, $user); // returns whether the given user has marked as liked the course or not Like::count($course); // returns the amount of like marks for the given course
Related Content on Laravel Daily
Video
Recent Courses on Laravel Daily
[NEW] Practical Laravel Security: Packages, Secrets, Supply-Chain Attacks
7 lessons
43 min read
Laravel 13 Eloquent: Expert Level
41 lessons
1 h 34 min
How to Structure Laravel 13 Projects
16 lessons
1 h 32 min read