laravel-interaction / bookmark
User bookmark/unbookmark behaviour for Laravel.
Installs: 4 562
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 4
Forks: 1
Open Issues: 1
Requires
- php: ^8.0
- illuminate/database: ^8.13 || ^9.0 || ^10.0 || ^11.0
- illuminate/support: ^8.0 || ^9.0 || ^10.0 || ^11.0
- laravel-interaction/support: ^1.0 || ^2.0 || ^3.0
Requires (Dev)
- mockery/mockery: ~1.3.3 || ^1.4.2
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0 || ^9.0
- phpunit/phpunit: ^9.3.3 || ^10.0
This package is auto-updated.
Last update: 2024-11-13 13:11:38 UTC
README
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
License
Laravel Bookmark is an open-sourced software licensed under the MIT license.