Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Build Status Scrutinizer Code Quality Code Coverage Build Status Code Intelligence Status Latest Stable Version Total Downloads Latest Unstable Version License

laravel collect

安装

使用 composer 安装:

$ composer require vetor/laravel-collect

模型迁移

运行模型迁移命令:

$ php artisan migrate

使用方法

User Model

use Illuminate\Foundation\Auth\User as Authenticatable;
use Vetor\Laravel\Collect\Collector\Models\Traits\Collector;
use Vetor\Contracts\Collect\Collector\Models\Collector as CollectorContract;

class User extends Authenticatable implements CollectorContract
{
    use Collector;
}

Article Model

use Vetor\Laravel\Collect\Collectable\Models\Traits\Collectable;
use Vetor\Contracts\Collect\Collectable\Models\Collectable as CollectableContract;

class Article extends Model implements CollectableContract
{
    use Collectable;
}

Available Methods

User

// 收藏

$user->collect($article);

// 是否收藏

$user->isCollectThis($article);

// 取消收藏

$user->cancelCollect($article);

// 用户的所有收藏记录

$user->collections;

// 用户收藏的文章记录

$user->collectionsWhereCollectable(Article::class);

Article

// 收藏

$article->collect();

// 是否收藏

$article->isCollection();

// 取消收藏

$article->cancelCollect();

注:默认为当前用户,可以把用户实例作为参数传入。

// 获取文章的收藏情况

$article->collections();

// 获取文章收藏数

$article->collections_count;

// 根据收藏数排序

Article::orderByCollectionsCount()->get();

注:升序 'asc';降序 'desc';默认为升序。

Collection

// 获取收藏表里所有文章

Collection::whereCollectable(Article::class)->get();

About

laravel collect (用于收藏功能的扩展包)

Resources

Packages

No packages published

Languages