lancodev / laravel-logging
This is my package laravel-logging
Requires
- php: ^8.2
- illuminate/contracts: ^11.0
- spatie/laravel-package-tools: ^1.13.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^10.0
- spatie/laravel-ray: ^1.26
README
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.