laravel-interaction/bookmark

User bookmark/unbookmark behaviour for Laravel.
5,080 10
Install
composer require laravel-interaction/bookmark
Latest Version:3.5.0
PHP:^8.0
License:MIT
Last Updated:Mar 18, 2026
Links: GitHub  ·  Packagist
Maintainer: zingimmick

Laravel Bookmark

User bookmark/unbookmark behaviour for Laravel.

Introduction

It let people express how they feel about the model(documentation/subject/topic).

Installation

Requirements

Instructions

Require Laravel Bookmark using Composer.

composer require laravel-interaction/bookmark

Publish configuration and migrations

php artisan vendor:publish --tag=bookmark-config
php artisan vendor:publish --tag=bookmark-migrations

Run database migrations.

php artisan migrate

Usage

Setup Bookmarker

use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Bookmark\Concerns\Bookmarker;

class User extends Model
{
    use Bookmarker;
}

Setup Bookmarkable

use Illuminate\Database\Eloquent\Model;
use LaravelInteraction\Bookmark\Concerns\Bookmarkable;

class Channel extends Model
{
    use Bookmarkable;
}

Bookmarker

use LaravelInteraction\Bookmark\Tests\Models\Channel;
/** @var \LaravelInteraction\Bookmark\Tests\Models\User $user */
/** @var \LaravelInteraction\Bookmark\Tests\Models\Channel $channel */
// Bookmark to Bookmarkable
$user->bookmark($channel);
$user->unbookmark($channel);
$user->toggleBookmark($channel);

// Compare Bookmarkable
$user->hasBookmarked($channel);
$user->hasNotBookmarked($channel);

// Get bookmarked info
$user->bookmarkableBookmarks()->count(); 

// with type
$user->bookmarkableBookmarks()->withType(Channel::class)->count(); 

// get bookmarked channels
Channel::query()->whereBookmarkedBy($user)->get();

// get bookmarked channels doesnt bookmarked
Channel::query()->whereNotBookmarkedBy($user)->get();

Bookmarkable

use LaravelInteraction\Bookmark\Tests\Models\User;
use LaravelInteraction\Bookmark\Tests\Models\Channel;
/** @var \LaravelInteraction\Bookmark\Tests\Models\User $user */
/** @var \LaravelInteraction\Bookmark\Tests\Models\Channel $channel */
// Compare Bookmarker
$channel->isBookmarkedBy($user); 
$channel->isNotBookmarkedBy($user);
// Get bookmarkers info
$channel->bookmarkers->each(function (User $user){
    echo $user->getKey();
});

$channels = Channel::query()->withCount('bookmarkers')->get();
$channels->each(function (Channel $channel){
    echo $channel->bookmarkers()->count(); // 1100
    echo $channel->bookmarkers_count; // "1100"
    echo $channel->bookmarkersCount(); // 1100
    echo $channel->bookmarkersCountForHumans(); // "1.1K"
});

Events

Event Fired
LaravelInteraction\Bookmark\Events\Bookmarked When an object get bookmarked.
LaravelInteraction\Bookmark\Events\Unbookmarked When an object get unbookmarked.

License

Laravel Bookmark is an open-sourced software licensed under the MIT license.

Related Packages

Version History

Version Released PHP Laravel License
3.5.0 ^8.0 ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT
3.4.0 ^8.0 ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0 MIT
3.3.0 ^8.0 ^8.0 || ^9.0 || ^10.0 || ^11.0 MIT
3.2.0 ^8.0 ^8.0 || ^9.0 || ^10.0 MIT
3.1.0 ^8.0 ^8.0 || ^9.0 || ^10.0 MIT
Pre-releases (5)
Version Released PHP Laravel License
2.0.0-beta.2 ^7.3 || ^8.0 ^8.0 || ^9.0 MIT
2.0.0-beta.1 ^7.3 || ^8.0 ^8.0 || ^9.0 MIT
1.0.0-alpha.3 ^7.2 || ^8.0 ^6.0 || ^7.0 || ^8.0 MIT
1.0.0-alpha.2 ^7.2 || ^8.0 ^6.0 || ^7.0 || ^8.0 MIT
1.0.0-alpha.1 ^7.2 || ^8.0 ^6.0 || ^7.0 || ^8.0 MIT