fbollon / lara-visitors
Laravel package that provides a dashboard and statistics for visits recorded by shetabit/visitor.
Requires
- php: ^8.2
- illuminate/routing: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- shetabit/visitor: ^4.5.6
Requires (Dev)
- laravel/pint: ^1.26
README
LaraVisitors is a Laravel package that provides a dashboard and statistics for visits recorded by shetabit/visitor.
β¨ Features
- Dashboard with visit statistics
- Date filters
- CSV export
- Charts (Chart.js)
- Stats by user, URL, browser, device
- Localization (EN/FR)
β Requirements
- Laravel 11 or higher
- PHP 8.2+
- shetabit/visitor 4.5.6 or higher
π¦ Installation
Install package via Composer:
composer require fbollon/lara-visitors
This package requires shetabit/visitor and will install it automatically if it is not already present.
βοΈ Configuration
Since this package also installs the shetabit/visitor package, we start with its configuration
1. Configure shetabit/visitor
Publish the configuration file:
php artisan vendor:publish --provider="Shetabit\Visitor\Provider\VisitorServiceProvider" --tag="config"
If needed, change the default table name in config/visitor.php:
// Name of the table where visit records should be saved 'table_name' => 'shetabit_visits',
Publish the migrations and run them:
php artisan vendor:publish --provider="Shetabit\Visitor\Provider\VisitorServiceProvider" --tag="migrations" php artisan migrate
Add the middleware to app/Http/Kernel.php to automatically log visits:
protected $middlewareGroups = [ 'web' => [ // other middlewares... \Shetabit\Visitor\Middlewares\LogVisits::class, ], ];
Add the trait to your User model:
use Shetabit\Visitor\Traits\Visitor; class User extends Model { use Visitor; }
2. Configure fbollon/lara-visitors
Publish the configuration file:
php artisan vendor:publish --tag=laravisitors-config
This will create config/laravisitors.php where you can customize:
- provide_assets: Load Bootstrap 5, Chart.js, and Font Awesome (set to
falseif your app already includes them). - layout: Define the layout used by package views.
- If you want to use the minimal layout provided by the package, you must set provide_assets to true.
- access_middleware: Middlewares applied to package routes.
- visits_table: Table name for visits (should match shetabit/visitor).
- user_model: Your User model class.
- user_display_attribute: User attribute to display in dashboard.
Optional: Publish assets (CSS/JS) if you want to customize them:
php artisan vendor:publish --tag=laravisitors-assets
Optional: Publish the layout if you want to override the default:
php artisan vendor:publish --tag=laravisitors-layout
Optional: Publish lang file, if you want to override :
php artisan vendor:publish --tag=laravisitors-translations
π Localization
LaraVisitors supports multiple languages (EN/FR).
To override translations:
php artisan vendor:publish --tag=laravisitors-translations
Files will be published to lang/vendor/laravisitors/{locale}/messages.php.
π Usage
Access the dashboard at:
/laravisitors/dashboard
β
Example config/laravisitors.php
return [ 'provide_assets' => true, 'layout' => 'laravisitors::layouts.minimal', 'access_middleware' => ['web', 'auth', 'laravisitors.access'], 'visits_table' => env('LARAVISITORS_TABLE', 'shetabit_visits'), 'user_model' => env('LARAVISITORS_USER_MODEL', App\Models\User::class), 'user_display_attribute' => 'name', ];
π Upgrading
Upgrade to 1.1.1
Version 1.1 introduces:
- Support for
shetabit/visitor4.5.6 or higher - Automatic loading of LaraVisitors migrations
- Improved dashboard performance through a database index on the
created_atcolumn of the visits table
Update the package:
composer update fbollon/lara-visitors
Run database migrations:
php artisan migrate
The migration included with LaraVisitors 1.1 automatically creates an index on the created_at column used by dashboard statistics queries.
This can significantly improve dashboard performance on applications with a large number of visit records.
π Contributing
Feel free to submit issues or pull requests on GitHub.
π License
This package is open-sourced software licensed under the MIT license.
