PHPackages                             jm-inc/laravel-viewable - 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. jm-inc/laravel-viewable

ActiveLibrary

jm-inc/laravel-viewable
=======================

A simple Laravel 8 package to count views for models.

0.1(4y ago)126MITPHP

Since Jul 16Pushed 4y agoCompare

[ Source](https://github.com/JM-Inc/laravel-viewable)[ Packagist](https://packagist.org/packages/jm-inc/laravel-viewable)[ RSS](/packages/jm-inc-laravel-viewable/feed)WikiDiscussions main Synced yesterday

READMEChangelogDependencies (2)Versions (2)Used By (0)

Laravel Viewable
================

[](#laravel-viewable)

[![Latest Stable Version](https://camo.githubusercontent.com/86e71b430bcef6cd61ce63451f6165d2d6726cba1fbcc051e44cbb041a8219fc/687474703a2f2f706f7365722e707567782e6f72672f6a6d2d696e632f6c61726176656c2d7669657761626c652f76)](https://packagist.org/packages/jm-inc/laravel-viewable)[![GitHub license](https://camo.githubusercontent.com/d96cb10226fdd6075875dc54bab559e70af45b8192f619ddec0010c8c48dc247/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4a4d2d496e632f6c61726176656c2d7669657761626c65)](https://github.com/JM-Inc/laravel-viewable/blob/main/LICENSE.md)[![GitHub Tests Action Status](https://camo.githubusercontent.com/51494b228c45d9a5825470134faf560c2bd0f19f969ec7773c2545e145061892/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6a6d2d696e632f6c61726176656c2d7669657761626c652f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/51494b228c45d9a5825470134faf560c2bd0f19f969ec7773c2545e145061892/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6a6d2d696e632f6c61726176656c2d7669657761626c652f72756e2d74657374733f6c6162656c3d7465737473)[![Total Downloads](https://camo.githubusercontent.com/365aacd2ee901f34ffb44d12844093dd416bfe5058ff2f250b855b068b00e34a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6d2d696e632f6c61726176656c2d7669657761626c65)](https://camo.githubusercontent.com/365aacd2ee901f34ffb44d12844093dd416bfe5058ff2f250b855b068b00e34a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6d2d696e632f6c61726176656c2d7669657761626c65)

A simple Laravel 8 package to count views for models.

Installation
------------

[](#installation)

```
composer require jm-inc/laravel-viewable
php artisan migrate
php artisan vendor:publish --tag=viewable-config # publish the configuration (optional)
```

Setup
-----

[](#setup)

1. Add this trait `JM\Viewable\InteractsWithViews` to the model you want to count views for.
2. In your `show` controller method, use `$model->viewed()` to count a view.
3. If the primary key of your model is not `id` set `$viewable_id = 'primary-key` in your model.

Example
-------

[](#example)

Your model should look like this:

```
