Laravel User Activity Log - a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app

Overview

Logo mark of Laravel User Activity Log

Laravel User Activity Log

yungts97/laravel-user-activity-log is a package for Laravel 8.x that provides easy to use features to log the activities of the users of your Laravel app. It provides automatic logging for the model events without complicated action. All activity will be stored in the logs table.

Environment Requirements

PHP: ^8.0

Laravel: ^8.x

Installation

You can install the package via composer:

composer require yungts97/laravel-user-activity-log

The package will automatically register a service provider.

After that, we still need one more step to complete the installation by run this command.

php artisan user-activity-log:install

How to use?

This package is very simple and easy to use. The only thing you need to do is add the Loggable trait in your model class.

use Illuminate\Database\Eloquent\Model;
use Yungts97\LaravelUserActivityLog\Traits\Loggable;

class Post extends Model
{
    use Loggable; // add it in here
    ...
}

It might troublesome if you have a lot of models. You could have a base class for your models and add Loggable trait in your base model.

# BaseModel.php
use Illuminate\Database\Eloquent\Model;
use Yungts97\LaravelUserActivityLog\Traits\Loggable;

class BaseModel extends Model
{
    use Loggable;
}

# PostModel.php
class Post extends BaseModel
{
    ...
}

If you don't want to log for any child class of the base model, you can add SkipLogging trait to skip the log for the model.

use Yungts97\LaravelUserActivityLog\Traits\SkipLogging;

class Post extends BaseModel
{
    use SkipLogging;
    ...
}

You can retrieve all activity using the Yungts97\LaravelUserActivityLog\Models\Log model.

Log::all();

Configuration

You can change the configuration of this package on config/user-activity-log.php.

[ 'logs', 'migrations', 'failed_jobs', 'password_resets', 'personal_access_tokens', ], # events to log 'events' => [ 'create' => true, 'edit' => true, 'delete' => true, 'login' => true, 'logout' => true ], # timezone for log date time 'timezone' => 'UTC' ];">
return [
    # add your own middleware here (route middleware)
    'middleware' => ['api', 'auth'],

    # user model
    'user_model' =>  "App\Models\User",

    # exclude tables for filter option
    'exclude_tables' => [
        'logs',
        'migrations',
        'failed_jobs',
        'password_resets',
        'personal_access_tokens',
    ],

    # events to log
    'events' => [
        'create' => true,
        'edit'   => true,
        'delete' => true,
        'login'  => true,
        'logout' => true
    ],

    # timezone for log date time
    'timezone' => 'UTC'
];

Routes

Endpoint Method Response Format Description
/logs GET JSON To retrieve user activity logs.
/logs/filter-options GET JSON To retrieve filter options for filtering logs.
/logs/{log_id} GET JSON To retrieve specific activity log.

Available paramaters for log filtering:

Parameter Type Description
page integer The page number for log pagination.
itemsPerPage integer The number item per page for log pagination
userId integer Filtering logs by the user ID.
logType string Filtering logs by log type.
tableName string Filtering logs by the table name.
dateFrom string Filtering logs by the date range. (Must have dateFrom & dateTo paramaters)
dateTo string Filtering logs by the date range. (Must have dateFrom & dateTo paramaters)

Exp. http://example.com/logs?page=1&itemsPerPage=10&userId=517

Sample Response

/logs

{
    "current_page": 1,
    "data": [
        {
            "id": 77,
            "user_id": 942,
            "log_datetime": "2022-01-22T05:56:57.000000Z",
            "table_name": null,
            "log_type": "login",
            "request_info": {
                "ip": "192.121.0.56",
                "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
            },
            "data": null,
            "current_data": null,
            "humanize_datetime": "17 seconds ago",
            "user": {
                "id": 1,
                "name": "User 1",
            }
        },
    ],
    "first_page_url": "http://localhost/api/logs?page=1",
    "from": 1,
    "last_page": 1,
    "last_page_url": "http://localhost/api/logs?page=1",
    "links": [
        {
            "url": null,
            "label": "ยซ Previous",
            "active": false
        },
        {
            "url": "http://localhost/api/logs?page=1",
            "label": "1",
            "active": true
        },
    ],
    "next_page_url": null,
    "path": "http://localhost/api/logs",
    "per_page": "10",
    "prev_page_url": null,
    "to": 10,
    "total": 1
}

/logs/filter-options

{
    "table_names": [
        "posts",
        "users",
    ],
    "log_types": [
        "create",
        "edit",
        "delete",
        "login",
        "logout"
    ]
}

/logs/77

{
            "id": 77,
            "user_id": 942,
            "log_datetime": "2022-01-22T05:56:57.000000Z",
            "table_name": null,
            "log_type": "login",
            "request_info": {
                "ip": "192.121.0.56",
                "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
            },
            "data": null,
            "current_data": null,
            "humanize_datetime": "17 seconds ago",
            "user": {
                "id": 1,
                "name": "User 1",
            }
        },

License

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

You might also like...
A simple Laravel event log package for easy model based logging.

Karacraft Logman A simple Model Event Logging Package Usage Installation composer require karacraft/logman Migrate php artisan migrate Publish php a

OPcodes's Log Viewer is a perfect companion for your Laravel app
OPcodes's Log Viewer is a perfect companion for your Laravel app

Log Viewer Easy-to-use, fast, and beautiful Features | Installation | Configuration | Authorization | Troubleshooting | Credits OPcodes's Log Viewer i

Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework.
Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework.

Your users do not always report errors, LaraBug does. LaraBug is a simple to use and implement error tracker built for the Laravel framework. This rep

Laravel breeze is a PHP Laravel library that provides Authentication features such as Login page , Register, Reset Password and creating all Sessions Required.

About Laravel breeze To give you a head start building your new Laravel application, we are happy to offer authentication and application starter kits

Log user authentication actions in Laravel.

Laravel Auth Log The laravel-auth-log package will log all the default Laravel authentication events (Login, Attempting, Lockout, etc.) to your databa

This package provides you with a simplistic `php artisan make:user` command

Laracademy Generators Laracademy make:user Command - provides you with a simplistic artisan command to generate users from the console. Author(s): Lar

Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and User Authentication.
Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and User Authentication.

Laravel Podcast is Laravel 5.5 web app that enables you to manage RSS feeds for your favorite podcasts and listen to the episodes in a seamless UI and

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

Laravel Package for TMDB API Wrapper A Laravel package that provides easy access to the php-tmdb/api TMDB (The Movie Database) API wrapper. This packa

Laravel telegram log is a package that can catch your logs all quite simply

Laravel Telegram log Laravel telegram log is a package that can catch your logs all quite simply. Requirments This package is tested with Laravel v8 i

Comments
  • add show events in user-activity-log

    add show events in user-activity-log

    hi, it's possible to add show event in user-activity-log?

    'events' => [ 'create' => true, 'edit' => true, 'delete' => true, 'login' => true, 'show' => true, 'logout' => true ],

    br Max

    opened by maxdiable 0
  • [Suggestion] Only logs fields that have been modified

    [Suggestion] Only logs fields that have been modified

    Let's suppose I have a table that has these column:

    • ID
    • name
    • price
    • description
    • id_event

    Then, I edit the field name and price in a view.

    Currently: logs->data will contain all the data of the record. What I would like to have: logs->data would only contains the name and the price. It could be an option.

    enhancement 
    opened by JeremieBergeron 9
Releases(v1.3.1)
Owner
null
This Package helps you in laravel application to log all desired activity for each request from request entry point to generate response at a single snapshot.

Laravel Scenario Logger This Package helps you in laravel application to log all desired activity for each request from request entry point to generat

Mehrdad Mahdian 6 Sep 27, 2021
Laravel Authentication Log is a package Log user authentication details and send new device notifications.

Laravel Authentication Log is a package which tracks your user's authentication information such as login/logout time, IP, Browser, Location, etc. as well as sends out notifications via mail, slack, or sms for new devices and failed logins.

Anthony Rappa 509 Sep 22, 2022
Filament-spatie-laravel-activitylog - View your activity logs inside of Filament. โšก๏ธ

View your activity logs inside of Filament. This package provides a Filament resource that shows you all of the activity logs created using the spatie

Ryan Chandler 35 Sep 21, 2022
Laravel Users | A Laravel Users CRUD Management Package

A Users Management Package that includes all necessary routes, views, models, and controllers for a user management dashboard and associated pages for managing Laravels built in user scaffolding. Built for Laravel 5.2, 5.3, 5.4, 5.5, 5.6, 5.7, 5.8, 6.0, 7.0 and 8.0.

Jeremy Kenedy 389 Sep 19, 2022
Configurable activity logger for filament.

Activity logger for filament Configurable activity logger for filament. Powered by spatie/laravel-activitylog Features You can choose what you want to

Ziyaan 46 Sep 13, 2022
Livewire DataTables components for back-end. Modular, easy to use, with tons of features.

Livewire DataTables Livewire DataTables components for back-end. Modular, easy to use, with tons of features. Inspired by Caleb's Livewire Screencasts

Amir Rami 8 Jul 27, 2022
This package provides a Logs page that allows you to view your Laravel log files in a simple UI

A simplistics log viewer for your Filament apps. This package provides a Logs page that allows you to view your Laravel log files in a simple UI. Inst

Ryan Chandler 9 Sep 17, 2022
Worlds (soon to be) most advanced Anime site! Featuring Administration features and everything you need for users and yourself. The successor of aniZero.

/**********************************************************************\ | _____ H33Tx & xHENAI __ 31.01.2022| |

HENAI.eu 33 Sep 19, 2022
Laravel Soulbscription - This package provides a straightforward interface to handle subscriptions and features consumption.

About This package provides a straightforward interface to handle subscriptions and features consumption. Installation You can

Lucas Vinicius 228 Sep 24, 2022
A simple blog app where a user can signup , login, like a post , delete a post , edit a post. The app is built using laravel , tailwind css and postgres

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nahom_zd 1 Mar 6, 2022