Download the PHP package rulr/laravel-authored without Composer
On this page you can find all versions of the php package rulr/laravel-authored. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rulr/laravel-authored
More information about rulr/laravel-authored
Files in rulr/laravel-authored
Package laravel-authored
Short Description A Laravel package that adds created_by and last_updated_by attributes to Eloquent models.
License MIT
Informations about the package laravel-authored
Laravel Authored
Introduction
rulr/laravel-authored is a Laravel package that automatically assigns created_by and updated_by user IDs to Eloquent models. This helps track which user created and last updated a model, improving data auditing and accountability.
Installation
You can install the package via Composer:
Usage
1. Apply the HasAuthor Trait
To enable automatic tracking, add the HasAuthor trait to your Eloquent models:
2. Use the authored Macro in Migrations
Instead of manually defining created_by and updated_by, you can use the provided macro when defining your schema:
3. Configuration
By default, this package uses created_by and updated_by columns. You can customize these field names by publishing and modifying the config file.
Publishing the Config File
This will create a file at config/authored.php, where you can modify the column names:
Now, when using $table->authored();, it will use the specified field names.
4. Automatically Set User IDs
When a user creates or updates a model, Laravel will automatically assign their ID:
Testing
This package includes PHPUnit tests using Orchestra Testbench. The tests create tables dynamically without requiring migrations. To run tests, use:
License
This package is open-source software licensed under the MIT license.
All versions of laravel-authored with dependencies
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/support Version ^10.0|^11.0|^12.0