PHP code example of mdbtq / laravel-page-views

1. Go to this page and download the library: Download mdbtq/laravel-page-views library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mdbtq / laravel-page-views example snippets


->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\Mdbtq\PageViews\Middleware\TrackPageView::class);
})

use Mdbtq\PageViews\PageViewRecorder;

$this->app->make(PageViewRecorder::class)->trackWhen(
    fn ($request) => ! $request->user()?->isAdmin()
);

use Mdbtq\PageViews\Events\PageViewRecorded;

Event::listen(PageViewRecorded::class, function (PageViewRecorded $event) {
    // $event->pageView
});
bash
php artisan vendor:publish --tag=page-views-migrations
bash
php artisan vendor:publish --tag=page-views-config