sansanlabs / laravel-userstamps
Package to add userstamps to models.
Fund package maintenance!
sansanlabs
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0||^12.0
- spatie/laravel-package-tools: ^1.92
Requires (Dev)
- larastan/larastan: ^2.9||^3.0
- laravel/pint: ^1.22
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^10.0.0||^9.0.0||^8.22.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.3||^2.0
- phpstan/phpstan-deprecation-rules: ^1.1||^2.0
- phpstan/phpstan-phpunit: ^1.3||^2.0
- spatie/laravel-ray: ^1.40.2
README
Installation
You can install the package via composer:
composer require sansanlabs/laravel-userstamps
You can publish the config file with:
php artisan vendor:publish --tag="userstamps-config"
This is the contents of the published config file:
return [ /* * Specify the column type used in the schema for the account ID * * Options: increments, bigIncrements, uuid, ulid * Default: bigIncrements */ "users_table_id_column_type" => "bigIncrements", /* * Specify the column name used as the foreign key reference for the account ID. Make sure all user tables have an ID column name that matches the one you define below. */ "users_table_id_column_name" => "id", /* * Specify the column that stores the ID of the user who initially created the entry */ "created_by_column" => "created_by", /* * Specify the column that holds the ID of the user who last updated the entry */ "updated_by_column" => "updated_by", /* * Specify the column that contains the ID of the user who removed the entry */ "deleted_by_column" => "deleted_by", /* * Indicate whether to include soft-deleted records in queries */ "with_trashed" => false, ];
Usage
Add the macro to your migration of your model
public function up(){ Schema::create('table_name', function (Blueprint $table) { ... $table->userstamps(); $table->softUserstamps(); }); }
Add the macro to your existing table
public function up() { Schema::table('table_name', function($table) { ... $table->userstamps(); $table->softUserstamps(); }); } public function down() { Schema::table('table_name', function($table) { $table->dropUserstamps(); $table->dropSoftUserstamps(); }); }
Add the Trait to your model
use SanSanLabs\UserStamps\Concerns\HasUserstamps; class Example extends Model { use HasUserstamps; }
There will be methods available to retrieve the user object which performs the action for creating, updating or deleting
$model->creator; // the user who created the model $model->editor; // the user who last updated the model $model->destroyer; // the user who deleted the model
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.