PHPackages                             vetor/laravel-collect - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vetor/laravel-collect

ActiveLibrary

vetor/laravel-collect
=====================

laravel collect

1.1.2(6y ago)10411MITPHPPHP ^7.0

Since Nov 15Pushed 6y ago1 watchersCompare

[ Source](https://github.com/VetorPers/laravel-collect)[ Packagist](https://packagist.org/packages/vetor/laravel-collect)[ RSS](/packages/vetor-laravel-collect/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/829afbfa46c4cf4e31dc428d4affcae4dd64ccfcaeb3a224158e332771d2c05b/68747470733a2f2f7472617669732d63692e6f72672f5665746f72506572732f6c61726176656c2d636f6c6c6563742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/VetorPers/laravel-collect)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/e1004a2ee7818a2b7d1295daccfc602c931c868647946dce39e1d3d0a2130e05/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5665746f72506572732f6c61726176656c2d636f6c6c6563742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/VetorPers/laravel-collect/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/4df3c16af9bf660c544f1a44577de7a3997a58aef6c8f0f288328134646c83cf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5665746f72506572732f6c61726176656c2d636f6c6c6563742f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/VetorPers/laravel-collect/?branch=master)[![Build Status](https://camo.githubusercontent.com/48bb76647f22438894b4495965011df037ee1fe6926754e4eae138b3e9eb158c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5665746f72506572732f6c61726176656c2d636f6c6c6563742f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/VetorPers/laravel-collect/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/5e0c8014cb7b9f3450a23a3dccf4ff32801f5390abc87a51b671b2188a64dfbd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f5665746f72506572732f6c61726176656c2d636f6c6c6563742f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![Latest Stable Version](https://camo.githubusercontent.com/19ec38408990f74cda5f8d3238f8b144be4391f54c127afd72774f4257b74b4e/68747470733a2f2f706f7365722e707567782e6f72672f7665746f722f6c61726176656c2d636f6c6c6563742f762f737461626c65)](https://packagist.org/packages/vetor/laravel-collect)[![Total Downloads](https://camo.githubusercontent.com/70e3b8adbc2a5fdad763d285d5dcda66dc1b24769a525aa7819c7ffdd0078c33/68747470733a2f2f706f7365722e707567782e6f72672f7665746f722f6c61726176656c2d636f6c6c6563742f646f776e6c6f616473)](https://packagist.org/packages/vetor/laravel-collect)[![Latest Unstable Version](https://camo.githubusercontent.com/cd36a624d7f9bde3b60e790a033b893a4e5e65d6db3e9e80013afaf326481bb2/68747470733a2f2f706f7365722e707567782e6f72672f7665746f722f6c61726176656c2d636f6c6c6563742f762f756e737461626c65)](https://packagist.org/packages/vetor/laravel-collect)[![License](https://camo.githubusercontent.com/ad324c7303772294238119b34fcc4176977aabf4adcd8026326721810a417e45/68747470733a2f2f706f7365722e707567782e6f72672f7665746f722f6c61726176656c2d636f6c6c6563742f6c6963656e7365)](https://packagist.org/packages/vetor/laravel-collect)

laravel collect
===============

[](#laravel-collect)

安装
--

[](#安装)

使用 composer 安装：

```
$ composer require vetor/laravel-collect
```

#### 模型迁移

[](#模型迁移)

运行模型迁移命令：

```
$ php artisan migrate
```

使用方法
----

[](#使用方法)

### User Model

[](#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

[](#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

[](#available-methods)

#### User

[](#user)

// 收藏

$user-&gt;collect($article);

// 是否收藏

$user-&gt;isCollectThis($article);

// 取消收藏

$user-&gt;cancelCollect($article);

// 用户的所有收藏记录

$user-&gt;collections;

// 用户收藏的文章记录

$user-&gt;collectionsWhereCollectable(Article::class);

#### Article

[](#article)

// 收藏

$article-&gt;collect();

// 是否收藏

$article-&gt;isCollection();

// 取消收藏

$article-&gt;cancelCollect();

> 注：默认为当前用户，可以把用户实例作为参数传入。

// 获取文章的收藏情况

$article-&gt;collections();

// 获取文章收藏数

$article-&gt;collections\_count;

// 根据收藏数排序

Article::orderByCollectionsCount()-&gt;get();

> 注：升序 'asc'；降序 'desc'；默认为升序。

#### Collection

[](#collection)

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

Collection::whereCollectable(Article::class)-&gt;get();

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~101 days

Total

3

Last Release

2534d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b09b2e1c11441a9b63c97370dff48819284356c22b188cb55e64be71337f1d9?d=identicon)[若相惜](/maintainers/%E8%8B%A5%E7%9B%B8%E6%83%9C)

---

Top Contributors

[![VetorPers](https://avatars.githubusercontent.com/u/16092592?v=4)](https://github.com/VetorPers "VetorPers (36 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vetor-laravel-collect/health.svg)

```
[![Health](https://phpackages.com/badges/vetor-laravel-collect/health.svg)](https://phpackages.com/packages/vetor-laravel-collect)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
