定制 laravel-interaction/bookmark 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laravel-interaction/bookmark

最新稳定版本:3.5.0

Composer 安装命令:

composer require laravel-interaction/bookmark

包简介

User bookmark/unbookmark behaviour for Laravel.

README 文档

README

User bookmark/unbookmark behaviour for Laravel.

Latest Stable Version Total Downloads Latest Unstable Version License

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.

统计信息

  • 总下载量: 5.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固