Search by

rahad9999 / activitylog

rahadabbas7

A clean, lightweight activity logging package for Laravel with pure Blade UI, standard Controllers, and REST API support.

Package info

github.com/rahadabbas7/activityLog

pkg:composer/rahad9999/activitylog

Statistics

Installs: 6

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-09-17 11:32 UTC

This package is auto-updated.

Last update: 2026-09-17 11:34:19 UTC


README

Latest Version on Packagist Total Downloads License

A clean, lightweight, and powerful activity logging system for Laravel applications with pure Laravel Blade UI, standard Controllers (no Livewire required), and a full RESTful API.

โœจ Features

  • ๐ŸŽฏ Simple & Direct API: Record logs directly with ActivityLog::record(), ActivityLog::recordCreated(), ActivityLog::recordUpdated(), ActivityLog::recordDeleted(), ActivityLog::recordCustom(), or activity_log() helper.
  • โšก Auto-Tracking Eloquent Trait: Add LogsActivity trait to any Eloquent model to automatically track created, updated (dirty diffs), deleted, and restored events.
  • ๐Ÿ–ฅ๏ธ Interactive Pure Blade Dashboard: Responsive timeline sidebar with date groups, live search, multi-filter dropdowns, bulk delete, and single log inspection without needing Livewire.
  • ๐ŸŒ Full RESTful API: Built-in endpoints for listing, filtering, inspecting, bulk deleting, and managing date groups for mobile & headless apps. (View API Documentation)
  • ๐Ÿงน Interactive Clean Artisan Command: php artisan activitylog:clean prompts for specific dates or automatically prunes logs older than retention days.
  • ๐ŸŽจ Dark / Light Mode: Built-in support for theme switching with Tailwind CSS.

๐Ÿ“ฆ Installation

You can install the package via Composer:

composer require rahad9999/activitylog

Run the interactive installer to publish the configuration and migrations:

php artisan activitylog:install

Or publish them manually:

php artisan vendor:publish --tag="activitylog-config"
php artisan vendor:publish --tag="activitylog-migrations"
php artisan migrate

โš™๏ธ Configuration

The package configuration file is saved at config/activitylog.php:

return [
    // Table name
    'table_name' => 'activity_logs',

    // Model class
    'model' => \Rahad\ActivityLog\Models\ActivityLog::class,

    // Global toggle
    'enabled' => true,

    // Automatic retention in days (used by cleaner command)
    'delete_records_older_than_days' => 365,

    // Web UI Settings
    'web' => [
        'enabled' => true,
        'route_prefix' => 'activity-logs',
        'middleware' => ['web', 'auth'],
        'layout' => 'activitylog::layouts.blank',
        'title' => 'Activity Log',
        'per_page' => 20,
        'home_url' => '/',
    ],

    // REST API Settings
    'api' => [
        'enabled' => true,
        'route_prefix' => 'api/activity-logs',
        'middleware' => ['api'],
        'per_page' => 20,
    ],
];

๐Ÿš€ Usage

1. Direct Static Logging

use Rahad\ActivityLog\Models\ActivityLog;

// Generic log
ActivityLog::record(
    title: 'User updated profile',
    module: 'User',
    action: 'updated',
    subject: $user,
    old: ['email' => 'old@example.com'],
    new: ['email' => 'new@example.com'],
    metadata: ['ip_country' => 'US']
);

// Event shortcuts
ActivityLog::recordCreated(module: 'Course', subject: $course, new: $course->toArray());
ActivityLog::recordUpdated(module: 'Course', subject: $course, old: $old, new: $new);
ActivityLog::recordDeleted(module: 'Course', subject: $course, old: $old);
ActivityLog::recordCustom(title: 'User logged in', module: 'Auth', action: 'login');

2. Global Helper Function

// Quick custom log
activity_log('Password changed', 'Auth', 'password_change', $user);

// Query builder
$recentLogs = activity_log()->module('User')->today()->get();

3. Automatic Eloquent Model Tracking

Add the LogsActivity trait to any Eloquent model to automatically track changes:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rahad\ActivityLog\Concerns\LogsActivity;

class Post extends Model
{
    use LogsActivity;

    // Optional: customize the module name
    protected string $activityModule = 'Blog';

    // Optional: ignore specific attributes from tracking
    protected array $activityIgnoredAttributes = ['view_count', 'updated_at'];
}

4. Querying Logs on Models

Add the HasActivityLogs trait to your User model:

use Rahad\ActivityLog\Concerns\HasActivityLogs;

class User extends Authenticatable
{
    use HasActivityLogs;
}

// Access activities performed by this user:
$user->activitiesAsCauser;

// Access activities where this model was the subject:
$post->activitiesAsSubject;

๐Ÿงน Cleaning & Pruning Logs

Clean activity logs using the artisan command:

# Interactive mode (prompts to enter a date or use retention policy):
php artisan activitylog:clean

# Delete logs for a specific date:
php artisan activitylog:clean --date=2026-09-15

# Delete logs older than 30 days:
php artisan activitylog:clean --days=30

# Force delete without confirmation:
php artisan activitylog:clean --date=2026-09-15 --force

๐ŸŒ Web Dashboard & API

Web Dashboard

Navigate to:

http://your-domain.test/activity-logs

RESTful API

Access JSON endpoints under:

http://your-domain.test/api/activity-logs

For full API endpoint specifications and JSON schema examples, see docs/api.md.

๐Ÿงช Testing

composer test

๐Ÿ“„ License

The MIT License (MIT). Please see License File for more information.