PHPackages                             muzidudu/laravel-record - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. muzidudu/laravel-record

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

muzidudu/laravel-record
=======================

User record features for Laravel Application.

02PHP

Since Oct 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/muzidudu/laravel-record)[ Packagist](https://packagist.org/packages/muzidudu/laravel-record)[ RSS](/packages/muzidudu-laravel-record/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Record
--------------

[](#laravel-record)

❤️ User record feature for Laravel Application.

[![CI](https://github.com/overtrue/laravel-record/workflows/CI/badge.svg)](https://github.com/overtrue/laravel-record/actions)[![Latest Stable Version](https://camo.githubusercontent.com/849d59a14d87b7d9f43cde45d9791466ad30c7350d9514a4b1fe20aa93a8f5fd/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d7265636f72642f762f737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-record)[![Latest Unstable Version](https://camo.githubusercontent.com/0a0b8c81a4aae50de3e31c18f81bec3891d7a6c9656467045876f4ed99cb6aeb/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d7265636f72642f762f756e737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-record)[![Total Downloads](https://camo.githubusercontent.com/0d66bccd7be38bc7ad922585c427635dd10479f02291070580cd42045eaebc29/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d7265636f72642f646f776e6c6f616473)](https://packagist.org/packages/overtrue/laravel-record)[![License](https://camo.githubusercontent.com/85d0a4b18a31afa24fc9978904532a8d1fe3961972b2c6a47c000d6393de3823/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d7265636f72642f6c6963656e7365)](https://packagist.org/packages/overtrue/laravel-record)

[![Sponsor me](https://github.com/overtrue/overtrue/raw/master/sponsor-me-button-s.svg?raw=true)](https://github.com/sponsors/overtrue)

Installing
----------

[](#installing)

```
composer require muzidudu/laravel-record -vvv
```

### Configuration &amp; Migrations

[](#configuration--migrations)

```
php artisan vendor:publish
```

Usage
-----

[](#usage)

### Traits

[](#traits)

#### `Muzidudu\LaravelRecord\Traits\Recorder`

[](#muzidudularavelrecordtraitsrecorder)

```
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Muzidudu\LaravelRecord\Traits\Recorder;

class User extends Authenticatable
{
    use Recorder;

}
```

#### `Muzidudu\LaravelRecord\Traits\Recordable`

[](#muzidudularavelrecordtraitsrecordable)

```
use Illuminate\Database\Eloquent\Model;
use Muzidudu\LaravelRecord\Traits\Recordable;

class Post extends Model
{
    use Recordable;

}
```

### API

[](#api)

```
$user = User::find(1);
$post = Post::find(2);

$user->record($post);
$user->unrecord($post);
$user->toggleRecord($post);
$user->getRecordItems(Post::class)

$user->hasRecorded($post);
$post->hasBeenRecordedBy($user);
```

#### Get object recorders:

[](#get-object-recorders)

```
foreach($post->recorders as $user) {
    // echo $user->name;
}
```

#### Get Record Model from User.

[](#get-record-model-from-user)

Used Recorder Trait Model can easy to get Recordable Models to do what you want. \_note: this method will return a `Illuminate\Database\Eloquent\Builder` \_

```
$user->getRecordItems(Post::class);

// Do more
$favortePosts = $user->getRecordItems(Post::class)->get();
$favortePosts = $user->getRecordItems(Post::class)->paginate();
$favortePosts = $user->getRecordItems(Post::class)->where('title', 'Laravel-Record')->get();
```

### Aggregations

[](#aggregations)

```
// all
$user->records()->count();

// with type
$user->records()->withType(Post::class)->count();

// recorders count
$post->recorders()->count();
```

List with `*_count` attribute:

```
$users = User::withCount('records')->get();

foreach($users as $user) {
    echo $user->records_count;
}

// for Recordable models:
$posts = Post::withCount('recorders')->get();

foreach($posts as $post) {
    echo $post->records_count;
}
```

### Attach user record status to recordable collection

[](#attach-user-record-status-to-recordable-collection)

You can use `Recorder::attachRecordStatus($recordables)` to attach the user record status, it will set `has_recorded` attribute to each model of `$recordables`:

#### For model

[](#for-model)

```
$post = Post::find(1);

$post = $user->attachRecordStatus($post);

// result
[
    "id" => 1
    "title" => "Add socialite login support."
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_recorded" => true
 ],
```

#### For `Collection | Paginator | LengthAwarePaginator | array`:

[](#for-collection--paginator--lengthawarepaginator--array)

```
$posts = Post::oldest('id')->get();

$posts = $user->attachRecordStatus($posts);

$posts = $posts->toArray();

// result
[
  [
    "id" => 1
    "title" => "Post title1"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_recorded" => true
  ],
  [
    "id" => 2
    "title" => "Post title2"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_recorded" => false
  ],
  [
    "id" => 3
    "title" => "Post title3"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_recorded" => true
  ],
]
```

#### For pagination

[](#for-pagination)

```
$posts = Post::paginate(20);

$user->attachRecordStatus($posts);
```

### N+1 issue

[](#n1-issue)

To avoid the N+1 issue, you can use eager loading to reduce this operation to just 2 queries. When querying, you may specify which relationships should be eager loaded using the `with` method:

```
// Recorder
$users = User::with('records')->get();

foreach($users as $user) {
    $user->hasRecorded($post);
}

// Recordable
$posts = Post::with('records')->get();
// or
$posts = Post::with('recorders')->get();

foreach($posts as $post) {
    $post->isRecordedBy($user);
}
```

### Events

[](#events)

**Event****Description**`Muzidudu\LaravelRecord\Events\Recorded`Triggered when the relationship is created.`Muzidudu\LaravelRecord\Events\Unrecorded`Triggered when the relationship is deleted.Related packages
----------------

[](#related-packages)

- Follow: [overtrue/laravel-follow](https://github.com/overtrue/laravel-follow)
- Like: [overtrue/laravel-like](https://github.com/overtrue/laravel-like)
- Record: [overtrue/laravel-record](https://github.com/overtrue/laravel-record)
- Subscribe: [overtrue/laravel-subscribe](https://github.com/overtrue/laravel-subscribe)
- Vote: [overtrue/laravel-vote](https://github.com/overtrue/laravel-vote)
- Bookmark: overtrue/laravel-bookmark (working in progress)

Contributing
------------

[](#contributing)

You can contribute in one of three ways:

1. File bug reports using the [issue tracker](https://github.com/overtrue/laravel-records/issues).
2. Answer questions or fix bugs on the [issue tracker](https://github.com/overtrue/laravel-records/issues).
3. Contribute new features or update the wiki.

*The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.*

❤️ Sponsor me
-------------

[](#heart-sponsor-me)

[![Sponsor me](https://github.com/overtrue/overtrue/raw/master/sponsor-me.svg?raw=true)](https://github.com/sponsors/overtrue)

如果你喜欢我的项目并想支持它，[点击这里 ❤️](https://github.com/sponsors/overtrue)

Project supported by JetBrains
------------------------------

[](#project-supported-by-jetbrains)

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

[![](https://camo.githubusercontent.com/3cf726e7cdadba47755b7f7ea4227945a92a2fa48aadf4a2573140ec6501c989/68747470733a2f2f7265736f75726365732e6a6574627261696e732e636f6d2f73746f726167652f70726f64756374732f636f6d70616e792f6272616e642f6c6f676f732f6a625f6265616d2e737667)](https://www.jetbrains.com/?from=https://github.com/overtrue)

PHP 扩展包开发
---------

[](#php-扩展包开发)

> 想知道如何从零开始构建 PHP 扩展包？
>
> 请关注我的实战课程，我会在此课程中分享一些扩展开发经验 —— [《PHP 扩展包实战教程 - 从入门到发布》](https://learnku.com/courses/creating-package)

License
-------

[](#license)

MIT

###  Health Score

14

—

LowBetter than 3% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity24

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a51a3575854b314e4dbf9be1c738b0a077853b7305f7cb323fa9d4276e52843c?d=identicon)[kaisenlee](/maintainers/kaisenlee)

---

Top Contributors

[![muzidudu](https://avatars.githubusercontent.com/u/9375220?v=4)](https://github.com/muzidudu "muzidudu (1 commits)")

### Embed Badge

![Health badge](/badges/muzidudu-laravel-record/health.svg)

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

###  Alternatives

[league/oauth2-client

OAuth 2.0 Client Library

3.8k115.1M1.0k](/packages/league-oauth2-client)[google/auth

Google Auth Library for PHP

1.4k266.3M128](/packages/google-auth)[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k98.4M89](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99895.6M97](/packages/league-oauth1-client)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70316.0M32](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41720.5M102](/packages/league-oauth2-google)

PHPackages © 2026

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