PHPackages                             almosabbirrakib/laravel-activity-log - 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. [Templating &amp; Views](/categories/templating)
4. /
5. almosabbirrakib/laravel-activity-log

ActiveLibrary[Templating &amp; Views](/categories/templating)

almosabbirrakib/laravel-activity-log
====================================

A comprehensive Laravel package for logging user activities with support for Blade, Vue 2, and Vue 3 frontends

v1.0.2(5mo ago)311MITPHPPHP ^8.0|^8.1|^8.2

Since Nov 17Pushed 5mo agoCompare

[ Source](https://github.com/mosabbirrakib/laravel-activity-log)[ Packagist](https://packagist.org/packages/almosabbirrakib/laravel-activity-log)[ RSS](/packages/almosabbirrakib-laravel-activity-log/feed)WikiDiscussions package Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (0)

Laravel Activity Log
====================

[](#laravel-activity-log)

[![Total Downloads](https://camo.githubusercontent.com/38e494f045162827dc852d672ed6835377d4fa980aed84bcc0afcb3a13134069/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616c6d6f73616262697272616b69622f6c61726176656c2d61637469766974792d6c6f67)](https://packagist.org/packages/almosabbirrakib/laravel-activity-log)[![Latest Stable Version](https://camo.githubusercontent.com/6ad4d4211935a48c37d5478ae243dc6ea5e33929a555f7e6cb7c2b3b798e9b13/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c6d6f73616262697272616b69622f6c61726176656c2d61637469766974792d6c6f67)](https://packagist.org/packages/almosabbirrakib/laravel-activity-log)[![License](https://camo.githubusercontent.com/d06ca9285376b2dc57ec1f249029139f5a8d68f6b54a5ac9091c3f1702e3e9c5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616c6d6f73616262697272616b69622f6c61726176656c2d61637469766974792d6c6f67)](https://packagist.org/packages/almosabbirrakib/laravel-activity-log)[![PHP Version](https://camo.githubusercontent.com/481470dca2aef65fba75959c9d37a7bdca407937b736ed73b59c730de66dd54e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616c6d6f73616262697272616b69622f6c61726176656c2d61637469766974792d6c6f67)](https://packagist.org/packages/almosabbirrakib/laravel-activity-log)

A comprehensive, production-ready Laravel package for logging and monitoring user activities with support for **Blade**, **Vue 2**, and **Vue 3** frontends. Track every action in your application with a beautiful, professional dashboard.

---

✨ Features
----------

[](#-features)

- 🎯 **Easy Integration** - Simple trait-based implementation, ready in minutes
- 🎨 **Multiple Frontend Options** - Choose between Blade, Vue 2, or Vue 3 components
- 📊 **Beautiful Dashboard** - Professional UI with Tailwind CSS and responsive design
- 🔍 **Advanced Filtering** - Search, filter by type, date range, user, and subject
- 📈 **Statistics Dashboard** - Real-time stats (total, today, this week, this month)
- 🚀 **High Performance** - Optimized queries with proper database indexing
- 🔒 **Secure by Default** - Configurable middleware, authentication, and sensitive data exclusion
- 📦 **Highly Configurable** - Extensive configuration options with sensible defaults
- 🧹 **Automatic Cleanup** - Built-in Artisan command for log retention management
- 🎭 **Multiple Log Types** - Created, updated, deleted, login, logout, and custom types
- 🔌 **RESTful API** - Complete API endpoints for external integrations
- 🌐 **Polymorphic Relations** - Track activities on any model
- 💾 **Flexible Storage** - Store additional metadata as JSON properties
- 🛠️ **Helper Functions** - Convenient global helpers for quick logging
- 📱 **Mobile Responsive** - Works perfectly on all screen sizes

---

📋 Requirements
--------------

[](#-requirements)

- **PHP:** 8.0 or higher
- **Laravel:** 9.x, 10.x, or 11.x
- **Database:** MySQL 5.7+ / PostgreSQL 9.6+ / SQLite 3.8+

---

🚀 Quick Start
-------------

[](#-quick-start)

### Installation

[](#installation)

```
# Install the package
composer require almosabbirrakib/laravel-activity-log

# Run the installation command
php artisan activity-log:install

# Run migrations
php artisan migrate
```

### Basic Usage

[](#basic-usage)

```
use AlMosabbirRakib\ActivityLog\Facades\ActivityLog;

// Log a simple activity
ActivityLog::log('User viewed dashboard');

// Log with type and properties
ActivityLog::log('Settings updated', 'updated', [
    'theme' => 'dark',
    'language' => 'en'
]);

// Using helper functions
activity_log('User performed action');
activity_login();
activity_logout();
```

### Add to Your Models

[](#add-to-your-models)

```
use AlMosabbirRakib\ActivityLog\Traits\LogsActivity;

class Post extends Model
{
    use LogsActivity;
}

// Now all model events are automatically logged!
$post = Post::create(['title' => 'My Post']); // Logged
$post->update(['title' => 'Updated']); // Logged
$post->delete(); // Logged
```

### View Activity Logs

[](#view-activity-logs)

Visit the dashboard in your browser:

```
http://your-app.test/activity-logs

```

---

📖 Documentation
---------------

[](#-documentation)

### Table of Contents

[](#table-of-contents)

- [Installation Guide](#-installation)
- [Configuration](#-configuration)
- [Usage Examples](#-usage)
- [Frontend Integration](#-frontend-integration)
- [API Endpoints](#-api-endpoints)
- [Artisan Commands](#-artisan-commands)
- [Advanced Usage](#-advanced-usage)

---

🔧 Configuration
---------------

[](#-configuration)

After installation, configure the package in `config/activity-log.php`:

```
return [
    // Database table name
    'table_name' => 'activity_logs',

    // User model
    'user_model' => 'App\\Models\\User',

    // Routes
    'routes' => [
        'enabled' => true,
        'prefix' => 'activity-logs',
        'middleware' => ['web', 'auth'],
        'api_middleware' => ['api', 'auth:sanctum'],
    ],

    // Pagination
    'per_page' => 15,

    // Automatic logging
    'auto_log' => [
        'enabled' => false, // Set to true to enable
        'events' => ['created', 'updated', 'deleted'],
    ],

    // Log retention (null = keep forever)
    'retention_days' => 90,

    // Privacy settings
    'log_ip_address' => true,
    'log_user_agent' => true,

    // Excluded attributes (won't be logged)
    'excluded_attributes' => [
        'password',
        'remember_token',
        'api_token',
    ],
];
```

---

💡 Usage
-------

[](#-usage)

### Using the Trait (Recommended)

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

Add the `LogsActivity` trait to any model:

```
use AlMosabbirRakib\ActivityLog\Traits\LogsActivity;

class Post extends Model
{
    use LogsActivity;
}
```

Enable automatic logging in config:

```
'auto_log' => [
    'enabled' => true,
    'events' => ['created', 'updated', 'deleted'],
],
```

### Using the Facade

[](#using-the-facade)

```
use AlMosabbirRakib\ActivityLog\Facades\ActivityLog;

// Simple log
ActivityLog::log('User viewed dashboard');

// With type
ActivityLog::log('Report generated', 'export');

// With properties
ActivityLog::log('Settings updated', 'updated', [
    'old_theme' => 'light',
    'new_theme' => 'dark',
]);

// With subject
ActivityLog::log('Post published', 'published', [], $post);

// Predefined methods
ActivityLog::created($post);
ActivityLog::updated($post, 'Post content updated');
ActivityLog::deleted($post);
ActivityLog::login($user);
ActivityLog::logout($user);
```

### Using Helper Functions

[](#using-helper-functions)

```
// Simple logging
activity_log('User performed action');

// Predefined helpers
activity_created($post);
activity_updated($post, 'Post updated');
activity_deleted($post);
activity_login();
activity_logout();
```

### Controller Examples

[](#controller-examples)

```
class PostController extends Controller
{
    public function store(Request $request)
    {
        $post = Post::create($request->validated());

        ActivityLog::created($post, 'New post created: ' . $post->title);

        return redirect()->route('posts.show', $post);
    }

    public function update(Request $request, Post $post)
    {
        $oldTitle = $post->title;
        $post->update($request->validated());

        ActivityLog::updated($post, 'Post updated', [
            'old_title' => $oldTitle,
            'new_title' => $post->title,
        ]);

        return redirect()->route('posts.show', $post);
    }
}
```

### Retrieving Logs

[](#retrieving-logs)

```
use AlMosabbirRakib\ActivityLog\Models\ActivityLog;

// Get all logs
$logs = ActivityLog::latest()->paginate(15);

// Filter by type
$createdLogs = ActivityLog::ofType('created')->get();

// Filter by user
$userLogs = ActivityLog::forCauser($user)->get();

// Filter by subject
$postLogs = ActivityLog::forSubject($post)->get();

// Date range
$logs = ActivityLog::dateRange('2024-01-01', '2024-12-31')->get();

// Search
$logs = ActivityLog::search('login')->get();

// Combined filters
$logs = ActivityLog::ofType('updated')
    ->dateRange('2024-01-01', '2024-12-31')
    ->search('post')
    ->latest()
    ->paginate(20);

// From model relationships
$post = Post::find(1);
$logs = $post->activityLogs;

$user = User::find(1);
$activities = $user->causedActivities;
```

---

🎨 Frontend Integration
----------------------

[](#-frontend-integration)

### Blade (Default)

[](#blade-default)

The Blade view is automatically available at `/activity-logs`:

```

Activity Logs

@include('activity-log::index')
```

### Vue 2 Integration

[](#vue-2-integration)

```
// In resources/js/app.js
import Vue from 'vue';
import ActivityLogVue2 from './components/activity-log/ActivityLogVue2.vue';

Vue.component('activity-log', ActivityLogVue2);

new Vue({
    el: '#app',
});
```

```

```

### Vue 3 Integration

[](#vue-3-integration)

```
// In resources/js/app.js
import { createApp } from 'vue';
import ActivityLogVue3 from './components/activity-log/ActivityLogVue3.vue';

const app = createApp({
    components: {
        ActivityLogVue3
    }
});

app.mount('#app');
```

```

```

---

🔌 API Endpoints
---------------

[](#-api-endpoints)

All API endpoints are prefixed with `/api/activity-logs`:

### Get All Logs

[](#get-all-logs)

```
GET /api/activity-logs
```

**Query Parameters:**

- `page` - Page number (default: 1)
- `per_page` - Items per page (default: 15)
- `search` - Search in description
- `type` - Filter by type
- `date_from` - Start date (Y-m-d)
- `date_to` - End date (Y-m-d)
- `causer_id` - Filter by user ID
- `causer_type` - Filter by user type
- `subject_id` - Filter by subject ID
- `subject_type` - Filter by subject type

**Example:**

```
curl -X GET "http://your-app.test/api/activity-logs?page=1&per_page=15&type=created&search=post" \
  -H "Authorization: Bearer YOUR_TOKEN"
```

### Get Single Log

[](#get-single-log)

```
GET /api/activity-logs/{id}
```

### Get Log Types

[](#get-log-types)

```
GET /api/activity-logs/types
```

### Get Statistics

[](#get-statistics)

```
GET /api/activity-logs/stats
```

Returns:

```
{
    "total": 1250,
    "today": 45,
    "this_week": 320,
    "this_month": 890
}
```

### Cleanup Old Logs

[](#cleanup-old-logs)

```
DELETE /api/activity-logs/cleanup?days=90
```

---

🛠️ Artisan Commands
-------------------

[](#️-artisan-commands)

### Install Package Assets

[](#install-package-assets)

```
# Install all assets
php artisan activity-log:install

# Install specific assets
php artisan activity-log:install --config
php artisan activity-log:install --migrations
php artisan activity-log:install --views
php artisan activity-log:install --components

# Force overwrite existing files
php artisan activity-log:install --force
```

### Clean Old Logs

[](#clean-old-logs)

```
# Interactive cleanup
php artisan activity-log:clean

# Clean logs older than 30 days
php artisan activity-log:clean --days=30

# Force cleanup without confirmation
php artisan activity-log:clean --days=90 --force
```

### Scheduled Cleanup

[](#scheduled-cleanup)

Add to `app/Console/Kernel.php`:

```
protected function schedule(Schedule $schedule)
{
    // Clean logs older than 90 days, daily at 2 AM
    $schedule->command('activity-log:clean --days=90 --force')
             ->dailyAt('02:00');
}
```

---

🔥 Advanced Usage
----------------

[](#-advanced-usage)

### Custom Activity Descriptions

[](#custom-activity-descriptions)

```
class Post extends Model
{
    use LogsActivity;

    protected function getActivityDescription(string $type): string
    {
        return match ($type) {
            'created' => "New post created: {$this->title}",
            'updated' => "Post updated: {$this->title}",
            'deleted' => "Post deleted: {$this->title}",
            default => parent::getActivityDescription($type),
        };
    }
}
```

### Custom Activity Properties

[](#custom-activity-properties)

```
class Post extends Model
{
    use LogsActivity;

    protected function getActivityProperties(string $type): array
    {
        return [
            'title' => $this->title,
            'category' => $this->category->name,
            'author' => $this->author->name,
            'status' => $this->status,
        ];
    }
}
```

### Middleware for Automatic Request Logging

[](#middleware-for-automatic-request-logging)

Add to `app/Http/Kernel.php`:

```
protected $middlewareGroups = [
    'web' => [
        // ... other middleware
        \AlMosabbirRakib\ActivityLog\Middleware\LogActivity::class,
    ],
];
```

Or apply to specific routes:

```
Route::middleware(['auth', \AlMosabbirRakib\ActivityLog\Middleware\LogActivity::class])
    ->group(function () {
        Route::resource('posts', PostController::class);
    });
```

### E-commerce Example

[](#e-commerce-example)

```
// Order placed
ActivityLog::log('Order placed', 'order_placed', [
    'order_id' => $order->id,
    'total' => $order->total,
    'items_count' => $order->items->count(),
], $order);

// Payment processed
ActivityLog::log('Payment processed', 'payment', [
    'amount' => $payment->amount,
    'method' => $payment->method,
    'transaction_id' => $payment->transaction_id,
], $payment);
```

---

🎯 Use Cases
-----------

[](#-use-cases)

- **Audit Trails** - Track all changes to critical data
- **User Monitoring** - Monitor user actions and behavior
- **Security** - Detect suspicious activities
- **Compliance** - Meet regulatory requirements (GDPR, HIPAA, etc.)
- **Debugging** - Trace issues and understand user flows
- **Analytics** - Analyze user behavior patterns
- **Customer Support** - Help users by reviewing their activity history

---

🔒 Security
----------

[](#-security)

- **Authentication Required** - All routes protected by authentication middleware
- **Sensitive Data Exclusion** - Passwords and tokens automatically excluded
- **Configurable Privacy** - Control IP and user agent logging
- **API Authentication** - Laravel Sanctum support for API endpoints
- **Customizable Middleware** - Add your own authorization logic

---

⚡ Performance
-------------

[](#-performance)

- **Optimized Queries** - Proper database indexing on all searchable columns
- **Eager Loading** - Relationships loaded efficiently
- **Pagination** - Large datasets handled with pagination
- **Configurable Retention** - Automatic cleanup prevents database bloat
- **Minimal Overhead** - Lightweight implementation with no performance impact

---

🧪 Testing
---------

[](#-testing)

```
# Run tests (coming soon)
composer test
```

---

📝 Changelog
-----------

[](#-changelog)

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

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

---

🐛 Security Vulnerabilities
--------------------------

[](#-security-vulnerabilities)

If you discover a security vulnerability, please send an e-mail to Al Mosabbir Rakib via . All security vulnerabilities will be promptly addressed.

---

📄 License
---------

[](#-license)

The Laravel Activity Log package is open-sourced software licensed under the [MIT license](LICENSE.md).

---

👨‍💻 Author
----------

[](#‍-author)

**Al-Mosabbir Rakib**

- GitHub: [@almosabbirrakib](https://github.com/mosabbirrakib)
- Email:

---

🙏 Acknowledgments
-----------------

[](#-acknowledgments)

- Built with ❤️ for the Laravel community
- Inspired by the need for simple, beautiful activity logging
- Thanks to all contributors and users

---

Made with ❤️ by [Al-Mosabbir Rakib](https://github.com/mosabbirrakib)

⭐ If you find this package helpful, please consider giving it a star on GitHub! ⭐

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance70

Regular maintenance activity

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

3

Last Release

176d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.0.1PHP ^8.0|^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/b84b0ad8749c7482b829287318ea5a5e549f1a0353bba5064c410349569a666e?d=identicon)[almosabbirrakib](/maintainers/almosabbirrakib)

---

Top Contributors

[![mosabbirrakib](https://avatars.githubusercontent.com/u/34891461?v=4)](https://github.com/mosabbirrakib "mosabbirrakib (9 commits)")

---

Tags

laravelbladevueactivity-logaudit-loguser activity

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/almosabbirrakib-laravel-activity-log/health.svg)

```
[![Health](https://phpackages.com/badges/almosabbirrakib-laravel-activity-log/health.svg)](https://phpackages.com/packages/almosabbirrakib-laravel-activity-log)
```

###  Alternatives

[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)

PHPackages © 2026

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