PHPackages                             animelhd/animes-view - 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. animelhd/animes-view

ActiveLibrary

animelhd/animes-view
====================

User view features for Laravel Application.

071PHP

Since May 10Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/animelhd/animes-view)[ Packagist](https://packagist.org/packages/animelhd/animes-view)[ RSS](/packages/animelhd-animes-view/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel View
------------

[](#laravel-view)

❤️ User view feature for Laravel Application.

[![CI](https://github.com/overtrue/laravel-view/workflows/CI/badge.svg)](https://github.com/overtrue/laravel-view/actions)[![Latest Stable Version](https://camo.githubusercontent.com/aa507fc2425a62f20aa6c40695915b25955405d92f19e591dbe81f6114eecdc8/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d766965772f762f737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-view)[![Latest Unstable Version](https://camo.githubusercontent.com/10cf0c92c2590db13a6951054c7e319ad961f392e8ebb1a2b3467d8840fc3d29/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d766965772f762f756e737461626c652e737667)](https://packagist.org/packages/overtrue/laravel-view)[![Total Downloads](https://camo.githubusercontent.com/8ff0f8fa82a98bd644df4d7d21f42926864f50754e31eb31f19479a5a62be88f/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d766965772f646f776e6c6f616473)](https://packagist.org/packages/overtrue/laravel-view)[![License](https://camo.githubusercontent.com/66fa38198216d995af9b1b66c90b534ae75802632931168a696b00a9393d3759/68747470733a2f2f706f7365722e707567782e6f72672f6f766572747275652f6c61726176656c2d766965772f6c6963656e7365)](https://packagist.org/packages/overtrue/laravel-view)

[![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 animelhd/animes-view -vvv
```

### Configuration &amp; Migrations

[](#configuration--migrations)

```
php artisan vendor:publish --provider="Animelhd\AnimesView\ViewServiceProvider"
```

Usage
-----

[](#usage)

### Traits

[](#traits)

#### `Animelhd\AnimesView\Traits\Viewer`

[](#animelhdanimesviewtraitsviewer)

```
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Animelhd\AnimesView\Traits\Viewer;

class User extends Authenticatable
{
    use Viewer;

}
```

#### `Animelhd\AnimesView\Traits\Vieweable`

[](#animelhdanimesviewtraitsvieweable)

```
use Illuminate\Database\Eloquent\Model;
use Animelhd\AnimesView\Traits\Vieweable;

class Post extends Model
{
    use Vieweable;

}
```

### API

[](#api)

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

$user->view($post);
$user->unview($post);
$user->toggleView($post);
$user->getViewItems(Post::class)

$user->hasViewed($post);
$post->hasBeenViewedBy($user);
```

#### Get object viewers:

[](#get-object-viewers)

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

#### Get View Model from User.

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

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

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

// Do more
$viewPosts = $user->getViewItems(Post::class)->get();
$viewPosts = $user->getViewItems(Post::class)->paginate();
$viewPosts = $user->getViewItems(Post::class)->where('title', 'Laravel-View')->get();
```

### Aggregations

[](#aggregations)

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

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

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

List with `*_count` attribute:

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

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

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

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

### Attach user view status to vieweable collection

[](#attach-user-view-status-to-vieweable-collection)

You can use `Viewer::attachViewStatus($vieweables)` to attach the user view status, it will set `has_viewed` attribute to each model of `$vieweables`:

#### For model

[](#for-model)

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

$post = $user->attachViewStatus($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_viewed" => true
 ],
```

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

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

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

$posts = $user->attachViewStatus($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_viewed" => true
  ],
  [
    "id" => 2
    "title" => "Post title2"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_viewed" => false
  ],
  [
    "id" => 3
    "title" => "Post title3"
    "created_at" => "2021-05-20T03:26:16.000000Z"
    "updated_at" => "2021-05-20T03:26:16.000000Z"
    "has_viewed" => true
  ],
]
```

#### For pagination

[](#for-pagination)

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

$user->attachViewStatus($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:

```
// Viewer
$users = User::with('views')->get();

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

// with vieweable object
$users = User::with('views.vieweable')->get();

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

// Vieweable
$posts = Post::with('views')->get();
// or
$posts = Post::with('viewers')->get();

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

### Events

[](#events)

**Event****Description**`Animelhd\AnimesView\Events\Viewed`Triggered when the relationship is created.`Animelhd\AnimesView\Events\Unviewed`Triggered when the relationship is deleted.License
-------

[](#license)

MIT

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity14

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/efac36cdc88bc6d242b4cbb508d62ca73403962a61156e92dadedea02f599ae7?d=identicon)[animelhd](/maintainers/animelhd)

---

Top Contributors

[![animelhd](https://avatars.githubusercontent.com/u/110630973?v=4)](https://github.com/animelhd "animelhd (6 commits)")

### Embed Badge

![Health badge](/badges/animelhd-animes-view/health.svg)

```
[![Health](https://phpackages.com/badges/animelhd-animes-view/health.svg)](https://phpackages.com/packages/animelhd-animes-view)
```

PHPackages © 2026

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