PHP code example of mahmoud-mhamed / spatie-activitylog-browse
1. Go to this page and download the library: Download mahmoud-mhamed/spatie-activitylog-browse 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/ */
mahmoud-mhamed / spatie-activitylog-browse example snippets
Mhamed\SpatieActivitylogBrowse\ActivitylogBrowseServiceProvider::class,
'auto_log' => [
'enabled' => true,
'events' => ['created', 'updated', 'deleted'],
'models' => '*', // '*' = all models, or array of specific classes
'excluded_models' => [],
'log_name' => 'default',
'log_only_dirty' => true,
'excluded_attributes' => [
'password', 'remember_token',
'two_factor_secret', 'two_factor_recovery_codes',
],
'submit_empty_logs' => false,
'exclude_null_on_create' => false,
],
'request_data' => [
'enabled' => true,
'fields' => [
'url' => true, 'previous_url' => true,
'method' => true, 'route_name' => true,
],
],
'device_data' => [
'enabled' => true,
'fields' => ['ip' => true, 'user_agent' => true, 'referrer' => true],
],
'performance_data' => [
'enabled' => true,
'fields' => [
'request_duration' => true, // ms since LARAVEL_START
'memory_peak' => true, // bytes
'db_query_count' => true, // rtisan command name
],
],
'browse' => [
'enabled' => true,
'prefix' => 'activity-log',
'middleware' => ['web', 'auth'],
'per_page' => 25,
'gate' => null, // e.g. 'view-activity-log'
'password' => env('ACTIVITYLOG_BROWSE_PASSWORD'),
'available_locales' => ['en', 'ar'],
],
'retention' => [
'enabled' => true,
'default_days' => 90, // catch-all age limit
'max_rows' => 1_000_000, // null to disable
'max_size_mb' => 500, // null to disable
'per_model' => [
App\Models\AuditLog::class => 'forever',
App\Models\User::class => 365,
],
'per_log_name' => [
'security' => 365,
],
'chunk_size' => 1000,
'optimize_after' => true,
'schedule' => 'daily', // 'daily' | 'weekly' | 'monthly' | null
'schedule_time' => '03:00', // 24-hour HH:MM
],
'deletion_history' => [
'enabled' => true,
'path' => storage_path('activitylog-browse/deletion-history.json'),
'max_entries' => 500, // oldest are dropped first
'max_size_mb' => 3, // file is reset if exceeded
],
$user = User::create(['name' => 'John']); // Logged
$user->update(['name' => 'Jane']); // Logged
$user->delete(); // Logged
'excluded_models' => [
App\Models\TemporaryFile::class,
],
'attributes' => [
'first_name' => 'First Name',
'email' => 'Email Address',
'created_at' => 'Creation Date',
],
// config/app.php
'locale' => 'ar',
App::setLocale('ar');
'load_migrations' => false,
'browse' => [
'middleware' => ['web', 'auth', \Stancl\Tenancy\Middleware\InitializeTenancyByDomain::class],
],
bash
php artisan activitylog-browse:install
bash
# Spatie migration
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"
php artisan migrate
# Package config
php artisan vendor:publish --tag=activitylog-browse-config
# Views (optional)
php artisan vendor:publish --tag=activitylog-browse-views
# Language files (optional)
php artisan vendor:publish --tag=activitylog-browse-lang
# Migrations (optional — for multi-tenancy setups)
php artisan vendor:publish --tag=activitylog-browse-migrations
bash
php artisan vendor:publish --tag=activitylog-browse-migrations