PHP code example of binafy / laravel-user-monitoring

1. Go to this page and download the library: Download binafy/laravel-user-monitoring 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/ */

    

binafy / laravel-user-monitoring example snippets


/*
 * Configurations.
 */
'config' => [
    'routes' => [
        'file_path' => 'routes/user-monitoring.php',
    ],
],

'user' => [
    /*
     * User model.
     */
    'model' => 'App\Models\User',

    /*
     * Foreign Key column name.
     */
    'foreign_key' => 'user_id',

    /*
     * Users table name.
     */
    'table' => 'users',

    /*
     * The correct guard.
     */
    'guard' => 'web',

    /*
     * If you are using uuid or ulid you can change it for the type of foreign_key.
     *
     * When you are using ulid or uuid, you need to add related traits into the models.
     */
    'foreign_key_type' => 'id', // uuid, ulid, id
],

'user' => [
    ...

    /*
     * If you are using uuid or ulid you can change it for the type of foreign_key.
     *
     * When you are using ulid or uuid, you need to add related traits into the models.
     */
    'foreign_key_type' => 'uuid', // uuid, ulid, id
],

protected $middlewareGroups = [
    'web' => [
        ...
        \Binafy\LaravelUserMonitoring\Middlewares\VisitMonitoringMiddleware::class,
    ],

    'api' => [
        // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
        \Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
];

'visit_monitoring' => [
    /*
     * You can specify pages not to be monitored.
     */
    'except_pages' => [
        'home',
        'admin/dashboard',
    ],
],

'visit_monitoring' => [
    ...

    /*
     * If you want to delete visit rows after some days, you can change this to 360,
     * but if you don't like to delete rows you can change it to 0.
     *
     * For this feature you need Task-Scheduling => https://laravel.com/docs/10.x/scheduling
     */
    'delete_days' => 10,
],



namespace App\Console;

...
use Binafy\LaravelUserMonitoring\Commands\RemoveVisitMonitoringRecordsCommand;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     */
    protected function schedule(Schedule $schedule): void
    {
         $schedule->command(RemoveVisitMonitoringRecordsCommand::class)->hourly();
    }
}

'visit_monitoring' => [
    ...

    /*
     * If you want to disable visit monitoring, you can change it to false.
     */
    'turn_on' => true,
    
    ...
]

 'visit_monitoring' => [
        ...

        /*
         * If you want to disable visit monitoring in Ajax mode, set it to false.
         */
        'ajax_requests' => true,

        ...
    ],



namespace App\Models;

use Binafy\LaravelUserMonitoring\Traits\Actionable;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use Actionable;
}

'action_monitoring' => [
    ...
    
    /*
     * Monitor actions.
     *
     * You can set true/false for monitor actions like (store, update, and ...).
     */
    'on_store'      => false,
    'on_update'     => true,
    'on_destroy'    => true,
    'on_read'       => true,
    'on_restore'    => false,
    'on_replicate'  => false,
],

'authentication_monitoring' => [
    ...

    /*
     * You can set true/false for monitor login or logout. 
     */
    'on_login' => true,
    'on_logout' => true,
],
shell
php artisan vendor:publish --tag="laravel-user-monitoring-config"
shell
php artisan vendor:publish --tag="laravel-user-monitoring-migrations"
shell
php artisan vendor:publish --tag="laravel-user-monitoring-views"
shell
php artisan vendor:publish --tag="laravel-user-monitoring-middlewares"
shell
php artisan vendor:publish --tag="laravel-user-monitoring-routes"
shell
php artisan vendor:publish --provider="Binafy\LaravelUserMonitoring\Providers\LaravelUserMonitoringServiceProvider"
shell
php artisan vendor:publish --tag="laravel-user-monitoring-routes"