Laravel Essentials

must-have snippets to speed up Laravel development

JJiordi Viera
1 snippets
Updated 5 days ago
Public
Example of using cyrildewit/eloquent-viewable to record and count views on a model.
php
<?php
use CyrildeWit\EloquentViewable\Viewable;

class Post extends Model
{
    use Viewable;
}

// In your controller
views($post)->record();

// Get the total views
$totalViews = views($post)->count();
Jiordi Viera
Jiordi Viera
---