alifcoder/activity-log

A simple action activity log package for Laravel.

Installs: 35

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/alifcoder/activity-log

v1.0.11 2025-06-10 11:18 UTC

This package is auto-updated.

Last update: 2025-10-10 11:58:10 UTC


README

A simple, customizable Laravel package to log and store user activity across your application. Perfect for auditing, tracking changes, and monitoring actions within modules.

✨ Features

  • Logs authenticated user actions and request details
  • Stores activity in a dedicated activity_logs table
  • Supports parent-child log relationships
  • Customizable logging behavior
  • Easily extendable and minimalistic

πŸ“¦ Requirements

  • PHP >=8.2
  • Laravel ^11.0 || ^12.0

πŸš€ Installation

composer require alifcoder/activity-log

βš™οΈ Configuration & Migration

Publish the configuration and migration with:

php artisan vendor:publish --tag=activity-log

This will publish:

  • config/activity-log.php
  • database/migrations/xxxx_xx_xx_xxxxxx_create_activity_logs_table.php

Then run the migration:

php artisan migrate

πŸ§‘β€πŸ’» Usage

Logging a manual activity

ActivityLogger::log(new ActivityLogCreateDTO(
                log_type: 'custom',         // optional: log type
                user_id: 1,                 // optional: user_id
                url: 'http://example.com',  // optional: URL
                method: 'GET',              // optional: HTTP method
                request_body: '{}',         // optional: request body
                response_body: '{}',        // optional: response body
                ...                         // other parameters
        ));

🧱 Table Structure: activity_logs

Column Type Description
id UUID Primary key
parent_id UUID Link to parent log (optional)
log_type String Type of action (e.g. create)
user_id String Authenticated user ID
module String App module or context
route String Route name
url String Full URL accessed
model_id String Related model ID (optional)
model_type String Related model class (optional)
user_agent Text Browser/user-agent string
created_at DateTime When the log was created

🧹 Uninstall (Clean Up)

Run this command before removing the package:

php artisan activity-log:uninstall

It will:

  • Roll back the migration (calls down())
  • Delete related migration files
  • Remove the config file

Then remove the package:

composer remove alifcoder/activity-log

🀝 Contributing

Pull requests are welcome! For major changes, please open an issue first.

πŸͺͺ License

MIT License Β© Shukhratjon Yuldashev

πŸ“‘ Automatic Logging for All Requests

To log every request made to your Laravel application, you can use the provided middleware and HTTP macro.

βœ… 1. Register the Middleware

In your app/Http/Kernel.php, register the middleware globally or per group:

protected $middleware = [
    // ...
    \Alif\ActivityLog\Http\Middleware\ActivityLogMiddleware::class,
];

This will automatically log incoming HTTP requests, including route, URL, method, and user info.

βœ… 2. Log Outgoing HTTP Requests

The package extends Laravel’s Http client with a loggable() macro.

Example usage:

use Illuminate\Support\Facades\Http;

$response = Http::loggable()->get('https://example.com/api/data');

This logs outgoing HTTP calls made by your application.

🧩 Customization

You can customize what gets logged, ignored routes/methods, and the database connection via:

config/activity-log.php

πŸ“« Support

If you need help, feel free to contact Shukhratjon Yuldashev on Telegram.