A comprehensive activity tracking package for Laravel applications that logs various types of activities including authentication events, model changes, exceptions, route access, and database queries.
- π Authentication Tracking: Login, logout, failed attempts, lockouts, registrations, email verifications, and password resets
- π Model Changes: Create, update, delete, force delete, and restore operations
β οΈ Exception Logging: Various HTTP and system exceptions- π£οΈ Route Access: Track accessed routes with request details
- π Query Logging: Monitor database queries with execution time
- π± Device Information: Browser, operating system, and device type detection
- π Flexible Storage: Store logs in database or files
- βοΈ Highly Configurable: Extensive configuration options for each feature
All notable changes to this project will be documented in the CHANGELOG.md file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
You can install the package via composer:
composer require abdulbaset/activity-trackerPublish the configuration file:
php artisan vendor:publish --provider="Abdulbaset\ActivityTracker\Providers\ActivityTrackerServiceProvider"This will create a config/activity-tracker.php file where you can configure various aspects of the package.
After installing the package, you need to run the migrations to create the required database tables. To do this, use the following Artisan command:
php artisan migrate --path=vendor/abdulbaset/activity-tracker/src/database/migrationsuse ActivityTracker;
// Simple activity logging
ActivityTracker::log('User Profile', 'User updated their profile');
// Detailed activity logging
ActivityTracker::log(
'Order Created',
'New order #123 was created',
[
'properties' => [
'order_id' => 123,
'amount' => 99.99
]
]
);Add the Trackable trait to your model:
use Abdulbaset\ActivityTracker\Traits\Trackable;
class User extends Model
{
use Trackable;
}return [
'enabled' => env('ACTIVITY_TRACKER_ENABLED', true),
'log_method' => env('ACTIVITY_TRACKER_LOG_METHOD', 'database'), // 'database' or 'file'
'log_file_path' => storage_path('logs/activity_tracker.log'),
];'auth' => [
'enabled' => true,
'events' => [
'login' => true,
'logout' => true,
'failed' => true,
'lockout' => true,
'registered' => true,
'verified' => true,
'password_reset' => true,
],
],'models' => [
'enabled' => true,
'events' => [
'creating' => true,
'created' => true,
'updating' => true,
'updated' => true,
'deleting' => true,
'deleted' => true,
'force_deleting' => true,
'force_deleted' => true,
'restoring' => true,
'restored' => true,
],
'full_model_data' => false,
],'exceptions' => [
'enabled' => true,
'events' => [
'not_found' => true,
'unauthorized' => true,
'method_not_allowed' => true,
'too_many_requests' => true,
'conflict' => true,
'unprocessable_entity' => true,
'access_denied' => true,
'gone' => true,
'precondition_failed' => true,
'unsupported_media_type' => true,
'general' => true,
],
'include_trace' => false,
],'exclude' => [
'routes' => [
'horizon*',
'nova*',
'_debugbar*',
],
'models' => [],
'model_attributes' => [
'password',
'remember_token',
'api_token',
// ... other sensitive fields
],
],The package creates an activities table with the following structure:
| Column | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| subject | string | Activity subject |
| causer_type | string | Model type of the causer |
| causer_id | bigint | ID of the causer |
| model_type | string | Related model type |
| model_id | bigint | Related model ID |
| event | string | Event type |
| before | json | Previous state (for updates) |
| after | json | New state (for updates) |
| ip | string | IP address |
| headers | json | Request headers |
| query_parameters | json | URL query parameters |
| request_method | string | HTTP method |
| browser | string | Browser information |
| device_type | string | Device type |
| operating_system | string | OS information |
| referring_url | string | Referrer URL |
| current_url | string | Current URL |
| description | text | Activity description |
| properties | json | Additional properties |
| created_at | timestamp | Creation timestamp |
| updated_at | timestamp | Update timestamp |
The package includes an API resource for formatting activity logs:
use Abdulbaset\ActivityTracker\Resources\ActivityTrackerResource;
// In your controller
public function index()
{
$activities = ActivityTracker::latest()->paginate();
return ActivityTrackerResource::collection($activities);
}The package tracks the following events:
- Login
- Logout
- Failed Login
- Lockout
- Registration
- Email Verification
- Password Reset
- Creating/Created
- Updating/Updated
- Deleting/Deleted
- Force Deleting/Force Deleted
- Restoring/Restored
- Not Found
- Unauthorized
- Method Not Allowed
- Too Many Requests
- Conflict
- Unprocessable Entity
- Access Denied
- Gone
- Precondition Failed
- Unsupported Media Type
- General Exceptions
If you discover any security-related issues, please email AbdulbasetRedaSayedHF@Gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
For support:
- Email: AbdulbasetRedaSayedHF@Gmail.com
- Create an issue in the GitHub repository
Maintaining this package takes time and effort. If youβd like to support its development and keep it growing, you can:
- π Star this repository
- π’ Sharing it with others
- π οΈ Contribute by reporting issues or suggesting features
- β Buy me a coffee
- β€οΈ Become a sponsor on GitHub Sponsors
- π΅ Make a one-time donation via PayPal
Your support means a lot to me! Thank you for making this possible. π