lancodev/laravel-logging

This is my package laravel-logging

0.6 2024-02-27 14:44 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package provides a simple way to log events to a database table. It provides a convenient Loggable Trait to allow you to link your logs to a model. It also provides a Log model that you can use to query your logs.

Installation

You can install the package via composer:

composer require lancodev/laravel-logging

You can publish and run the migrations with:

php artisan vendor:publish --tag="laravel-logging-migrations"
php artisan migrate

Usage

Add the Loggable Trait to your model(s) that you want to log events for.

Then, you can create logs for the model using the logs relationship:

$model->logs()->create([
    'type' => 'Info',
    'log' => 'lorem ipsum',
]);

To view logs for a given model, you can use the logs relationship:

$model->logs;

Or use standard Eloquent query language to filter the logs by type, etc:

$model->logs()->where('type', 'Info')->get();

Lancodev\LaravelLogging\Models\Log {
  id: 1,
  loggable_type: "App\Models\{SOME_MODEL}",
  loggable_id: 1,
  type: "Info",
  log: "lorem ipsum",
  created_at: "2023-01-01 00:00:00",
  updated_at: "2023-01-01 00:00:00",
},

The Log model also has a loggable relationship that allows you to access the model that the log belongs to:

$log->loggable;****

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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