PHP code example of ntimes / route-time-limits

1. Go to this page and download the library: Download ntimes/route-time-limits 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/ */

    

ntimes / route-time-limits example snippets


// In your routes file
Route::get('/dashboard', 'DashboardController@index')
    ->name('dashboard')
    ->middleware('route.time.limit');

// Or for route groups
Route::middleware('route.time.limit')->group(function () {
    Route::get('/admin', 'AdminController@index')->name('admin.index');
    Route::get('/admin/users', 'AdminController@users')->name('admin.users');
});

return [
    // Default maximum time allowed for all routes (in seconds)
    'default_max_time' => [
        'guest' => 300, // 5 minutes for guests
        'authenticated' => 600, // 10 minutes for authenticated users
    ],

    // How many days of data to keep in the database
    'data_retention_days' => 1,

    // Custom route configurations
    // Format: 'route_name' => ['guest' => time_in_seconds, 'authenticated' => time_in_seconds]
    'custom_routes' => [
        'admin.dashboard' => [
            'guest' => 0, // No access for guests
            'authenticated' => 900, // 15 minutes for authenticated users
        ],
        'api.users.index' => [
            'guest' => 60, // 1 minute for guests
            'authenticated' => 300, // 5 minutes for authenticated users
        ],
    ],
    
    // Whether to enable the middleware globally
    'enabled' => true,
    
    // Routes to exclude from time tracking
    'excluded_routes' => [
        'login',
        'register',
    ],
    
    // Whether to track by IP address for guest users
    'track_guest_by_ip' => true,
    
    // Identify user by this field (default: id)
    'user_identifier' => 'id',
];
bash
php artisan vendor:publish --provider="NTimes\RouteTimeLimits\RouteTimeLimitsServiceProvider"
bash
php artisan migrate