PHPackages                             varatech/activity-monitor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. varatech/activity-monitor

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

varatech/activity-monitor
=========================

A lightweight, configurable Laravel package to log and monitor user activities

1.0.1(11mo ago)0111MITPHPPHP ^8.1|^8.2|^8.3

Since Jun 20Pushed 11mo agoCompare

[ Source](https://github.com/VaraAI/activity-monitor)[ Packagist](https://packagist.org/packages/varatech/activity-monitor)[ RSS](/packages/varatech-activity-monitor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

📦 **Laravel User Activity Monitor**
===================================

[](#-laravel-user-activity-monitor)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2f61358ced54bb19c1bd2d6c3de2f4b6c15b62d8bd58ab1d5f037802ebac1e89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76617261746563682f61637469766974792d6d6f6e69746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/varatech/activity-monitor)[![Total Downloads](https://camo.githubusercontent.com/fc040e5e5f0712fe14a038c0d862a806ba2527d585a41335dae6530b16b72695/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76617261746563682f61637469766974792d6d6f6e69746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/varatech/activity-monitor)[![License](https://camo.githubusercontent.com/18f8ff6a3710a02fa775fdc9e682bf466e41364293147ad1ba540f91f7044a8e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f76617261746563682f61637469766974792d6d6f6e69746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/varatech/activity-monitor)

> A lightweight, configurable Laravel package to **log and monitor user activities** in your application. Capture login, logout, CRUD actions, API requests, and more — complete with IP address, user agent, and custom properties.

---

✨ **Features**
--------------

[](#-features)

✅ **Automatic Activity Logging**: Automatically logs user actions (login, logout, create, update, delete)
✅ **Model Event Tracking**: Tracks model events for specified models
✅ **Rich Metadata**: Records user ID, IP address, user agent, URL, timestamps
✅ **Easy Querying**: Easy-to-query activity logs (`Activity::forUser($id)->recent()`)
✅ **Highly Configurable**: Enable/disable features via config
✅ **Extendable**: Hook into activity logging for custom actions
✅ **Clean Schema**: Clean database schema with optional JSON properties
✅ **Console Commands**: Built-in commands for cleanup and statistics
✅ **Traits Available**: Use `LogsActivity` trait for automatic model tracking
✅ **Laravel 9-12 Compatible**: Full support for Laravel 9.x, 10.x, 11.x, and 12.x
✅ **PHP 8.1-8.3 Ready**: Compatible with modern PHP versions

---

⚡ **Installation**
------------------

[](#-installation)

Install the package via Composer:

```
composer require varatech/activity-monitor
```

Publish the configuration and migration files:

```
php artisan vendor:publish --tag="activity-monitor-config"
php artisan vendor:publish --tag="activity-monitor-migrations"
```

Run the migrations:

```
php artisan migrate
```

---

🔧 **Configuration**
-------------------

[](#-configuration)

The package comes with a comprehensive configuration file. Here are the key options:

```
// config/activity-monitor.php
return [
    // Enable automatic request logging
    'log_all_requests' => env('ACTIVITY_LOG_ALL_REQUESTS', false),

    // Models to automatically track
    'track_models' => [
        App\Models\Post::class,
        App\Models\Order::class,
    ],

    // Authentication event logging
    'log_authentication_events' => [
        'login' => true,
        'logout' => true,
    ],

    // Model events to track
    'log_model_events' => [
        'created' => true,
        'updated' => true,
        'deleted' => true,
    ],

    // Properties to include with each log
    'log_properties' => [
        'ip_address' => true,
        'user_agent' => true,
        'url' => true,
        'method' => true,
    ],

    // Automatic cleanup settings
    'cleanup' => [
        'enabled' => false,
        'older_than_days' => 90,
    ],
];
```

---

🚀 **Usage**
-----------

[](#-usage)

### Manual Activity Logging

[](#manual-activity-logging)

```
use VaraTech\ActivityMonitor\Facades\ActivityMonitor;

// Basic activity logging
ActivityMonitor::log('custom_action', [
    'note' => 'Something important happened',
    'extra_data' => 'Additional context',
]);

// Log with subject (related model)
$post = Post::find(1);
ActivityMonitor::log('post_viewed', ['ip' => request()->ip()], $post, 'User viewed blog post');

// Log authentication events
ActivityMonitor::logAuth('login', auth()->user(), ['guard' => 'web']);

// Log HTTP requests
ActivityMonitor::logRequest(request(), ['custom_property' => 'value']);
```

### Using the LogsActivity Trait

[](#using-the-logsactivity-trait)

Add the trait to your models for automatic activity logging:

```
use VaraTech\ActivityMonitor\Traits\LogsActivity;

class Post extends Model
{
    use LogsActivity;

    // Now all created, updated, deleted events are automatically logged
}

// Manual logging on the model
$post = Post::find(1);
$post->logActivity('published', ['published_at' => now()], 'Post was published');

// Get all activities for a model
$activities = $post->activities;
```

### Querying Activities

[](#querying-activities)

The `Activity` model comes with helpful query scopes:

```
use VaraTech\ActivityMonitor\Models\Activity;

// Get recent activities for a user
$recent = Activity::forUser(auth()->id())->recent(20)->get();

// Get activities by action
$logins = Activity::byAction('auth.login')->get();

// Get today's activities
$today = Activity::today()->get();

// Get activities for a specific model
$postActivities = Activity::forSubject($post)->get();

// Get activities within date range
$activities = Activity::betweenDates(
    Carbon::now()->subWeek(),
    Carbon::now()
)->get();

// Complex queries
$activities = Activity::forUser(auth()->id())
    ->byAction('model.updated')
    ->where('subject_type', Post::class)
    ->recent(50)
    ->get();
```

### Working with Activity Properties

[](#working-with-activity-properties)

```
$activity = Activity::first();

// Get a property value
$ipAddress = $activity->getProperty('ip_address');
$customData = $activity->getProperty('custom_data', 'default_value');

// Check if property exists
if ($activity->hasProperty('user_agent')) {
    echo $activity->getProperty('user_agent');
}

// Access properties directly (JSON field)
$allProperties = $activity->properties;
```

---

🛠 **Advanced Usage**
--------------------

[](#-advanced-usage)

### Automatic Model Tracking

[](#automatic-model-tracking)

Configure models to be automatically tracked in your config:

```
// config/activity-monitor.php
'track_models' => [
    App\Models\User::class,
    App\Models\Post::class,
    App\Models\Order::class,
],
```

### Request Logging

[](#request-logging)

Enable automatic request logging:

```
// .env
ACTIVITY_LOG_ALL_REQUESTS=true
```

Or in config:

```
'log_all_requests' => true,
```

### Console Commands

[](#console-commands)

#### View Activity Statistics

[](#view-activity-statistics)

```
# Show stats for the last 30 days
php artisan activity-monitor:stats

# Show stats for the last 7 days
php artisan activity-monitor:stats --days=7

# Show stats for a specific user
php artisan activity-monitor:stats --user=123
```

#### Clean Up Old Activities

[](#clean-up-old-activities)

```
# Clean up activities older than configured days
php artisan activity-monitor:cleanup

# Clean up activities older than 30 days
php artisan activity-monitor:cleanup --days=30

# Dry run (see what would be deleted)
php artisan activity-monitor:cleanup --dry-run
```

---

📊 **Database Schema**
---------------------

[](#-database-schema)

The activities table includes these fields:

ColumnTypeDescription`id`bigintPrimary key`action`stringThe action performed`description`stringHuman-readable description`user_id`bigintID of the user who performed the action`user_type`stringClass name of the user model`subject_type`stringClass name of the subject model`subject_id`bigintID of the subject model`properties`jsonAdditional properties and metadata`ip_address`stringUser's IP address`user_agent`textUser's browser/client info`url`stringRequest URL`method`stringHTTP method`created_at`timestampWhen the activity occurred`updated_at`timestampLast updated---

🎯 **Example Use Cases**
-----------------------

[](#-example-use-cases)

### Audit Trails for Admin Actions

[](#audit-trails-for-admin-actions)

```
// In your admin controller
public function deleteUser(User $user)
{
    ActivityMonitor::log('admin.user_deleted', [
        'deleted_user_id' => $user->id,
        'deleted_user_email' => $user->email,
        'reason' => request('reason'),
    ], $user, "Admin deleted user: {$user->email}");

    $user->delete();
}
```

### Security Monitoring

[](#security-monitoring)

```
// Track suspicious login attempts
Event::listen(\Illuminate\Auth\Events\Failed::class, function ($event) {
    ActivityMonitor::log('auth.failed', [
        'email' => $event->credentials['email'] ?? null,
        'ip_address' => request()->ip(),
        'user_agent' => request()->userAgent(),
    ], null, 'Failed login attempt');
});
```

### API Usage Analytics

[](#api-usage-analytics)

```
// In your API middleware
public function handle($request, Closure $next)
{
    $response = $next($request);

    if ($request->is('api/*')) {
        ActivityMonitor::logRequest($request, [
            'api_version' => $request->header('API-Version'),
            'response_time' => microtime(true) - LARAVEL_START,
            'response_status' => $response->getStatusCode(),
        ]);
    }

    return $response;
}
```

### User Behavior Tracking

[](#user-behavior-tracking)

```
// Track user interactions
class PostController extends Controller
{
    public function show(Post $post)
    {
        $post->logActivity('viewed', [
            'referrer' => request()->header('referer'),
            'read_time_estimate' => strlen(strip_tags($post->content)) / 200, // words per minute
        ], 'User viewed blog post');

        return view('posts.show', compact('post'));
    }
}
```

---

🔒 **Security**
--------------

[](#-security)

If you discover any security-related issues, please email  instead of using the issue tracker.

---

🧪 **Testing**
-------------

[](#-testing)

```
composer test
```

---

📈 **Performance Tips**
----------------------

[](#-performance-tips)

1. **Selective Logging**: Only enable the logging you need
2. **Database Indexing**: The migration includes proper indexes for common queries
3. **Regular Cleanup**: Use the cleanup command or enable automatic cleanup
4. **Async Processing**: Consider queuing activity logging for high-traffic applications

---

🤝 **Contributing**
------------------

[](#-contributing)

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

---

📝 **Changelog**
---------------

[](#-changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for more information on what has changed recently.

---

📄 **License**
-------------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

---

🏢 **About VaraAI**
------------------

[](#-about-varaai)

**Vara-AI Tech** is a technology company specializing in Laravel packages and SaaS solutions. We're building a comprehensive ecosystem of Laravel tools to help developers build better applications faster.

### 🚀 **Our Laravel Package Ecosystem**

[](#-our-laravel-package-ecosystem)

- **🔐 [Laravel SaaS Auth](https://github.com/VaraAI/laravel-saas-auth)** - Complete SaaS authentication system
- **📱 [VaraSMS](https://github.com/VaraAI/varasms)** - SMS integration package
- **⚡ [Recharge Meter](https://github.com/VaraAI/recharge-meter)** - Utility management system
- **📊 [Activity Monitor](https://github.com/VaraAI/activity-monitor)** - User activity logging *(this package)*

### 🌐 **Connect with VaraAI**

[](#-connect-with-varaai)

- **Organization**: [github.com/VaraAI](https://github.com/VaraAI)
- **Website**: [varaai.tech](https://varaai.tech)
- **YouTube**: [Vara AI Tech](https://www.youtube.com/@vara-ai-tech)
- **Location**: Korea, South
- **Management**: iPROTE Technology Company Limited

---

🌟 **Credits**
-------------

[](#-credits)

- [**Vara-AI Tech**](https://varaai.tech) - Lead Developer
- [**VaraAI Organization**](https://github.com/VaraAI) - Package Maintainer
- [**iPROTE Technology Company Limited**](https://github.com/VaraAI) - Management
- [All Contributors](https://github.com/VaraAI/activity-monitor/contributors)

### 📞 **Contact &amp; Support**

[](#-contact--support)

- **🌐 Website**: [varaai.tech](https://varaai.tech)
- **📧 Email**:
- **🐙 GitHub**: [@VaraAI](https://github.com/VaraAI)
- **📺 YouTube**: [@vara-ai-tech](https://www.youtube.com/@vara-ai-tech)
- **🐛 Issues**: [Report Issues](https://github.com/VaraAI/activity-monitor/issues)
- **💬 Discussions**: [GitHub Discussions](https://github.com/VaraAI/activity-monitor/discussions)

---

🔮 **Roadmap**
-------------

[](#-roadmap)

- **Dashboard UI** for activity logs
- **Export functionality** (CSV, JSON)
- **Real-time broadcasting** (WebSockets)
- **Notifications** on critical actions
- **Advanced filtering** and search
- **Performance optimizations**
- **Multi-tenant support**

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance52

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

333d ago

PHP version history (2 changes)1.0.0PHP ^8.1

1.0.1PHP ^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/faf71e910ca3cb7a04b902b131b838ceb4ce64576a0eca469ea932a71074235e?d=identicon)[Constantino2019-et](/maintainers/Constantino2019-et)

---

Top Contributors

[![Constantino2019-et](https://avatars.githubusercontent.com/u/80386833?v=4)](https://github.com/Constantino2019-et "Constantino2019-et (3 commits)")

---

Tags

laravelloggingmonitoringactivityAudit

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/varatech-activity-monitor/health.svg)

```
[![Health](https://phpackages.com/badges/varatech-activity-monitor/health.svg)](https://phpackages.com/packages/varatech-activity-monitor)
```

###  Alternatives

[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[rollbar/rollbar-laravel

Rollbar error monitoring integration for Laravel projects

14110.4M7](/packages/rollbar-rollbar-laravel)[muhammadsadeeq/laravel-activitylog-ui

A beautiful, modern UI for Spatie's Activity Log with advanced filtering, analytics, and real-time features.

17510.1k](/packages/muhammadsadeeq-laravel-activitylog-ui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
