laravel-userstamps maintained by turahe
Description
Adds user tracking fields to Laravel models.
Author
Last update
2025/12/15 10:27
(dev-dependabot/github_actions/actions/upload-artifact-6)
License
Downloads
285
Tags
Laravel Userstamps
A Laravel package to automatically add created_by, updated_by, and deleted_by fields to your Eloquent models, with enhanced configuration options, custom column types, and comprehensive testing infrastructure.
Features
- Core Functionality: Automatically tracks which user created, updated, or deleted a model
- Enhanced Configuration: Advanced options for customizing column types, names, and behavior
- Custom UserStamps: Support for custom column configurations and advanced use cases
- Multi-Database Support: Works with MySQL, PostgreSQL, and SQLite
- Laravel Compatibility: Supports Laravel 10, 11, and 12
- Database Schema Macros: Easy-to-use schema macros for userstamps
- Comprehensive Testing: GitHub Actions CI/CD with multi-database testing
- Docker Integration: Complete Docker setup for local development and testing
- Code Quality: Laravel Pint integration and security scanning
Installation
composer require turahe/laravel-userstamps
Usage
1. Basic Usage with HasUserStamps
use Turahe\UserStamps\Concerns\HasUserStamps;
class Post extends Model
{
use HasUserStamps;
}
2. Advanced Usage with HasCustomUserStamps
use Turahe\UserStamps\Concerns\HasCustomUserStamps;
class Post extends Model
{
use HasCustomUserStamps;
protected $userstampsConfig = [
'columns' => [
'created_by' => [
'type' => 'uuid',
'index' => true,
'comment' => 'User who created this post'
],
'updated_by' => [
'type' => 'uuid',
'nullable' => false
]
]
];
}
3. Database Schema
Add the userstamps columns using the provided schema macros:
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->userstamps(); // Adds created_by and updated_by
$table->softUserstamps(); // Adds deleted_by
$table->timestamps();
$table->softDeletes();
});
Configuration
Publish Configuration
php artisan vendor:publish --provider="Turahe\UserStamps\UserStampsServiceProvider" --tag="config"
Enhanced Configuration Options
The package now supports advanced configuration for customizing column behavior:
return [
'users_table' => 'users',
'users_table_column_type' => 'bigIncrements',
'users_table_column_id_name' => 'id',
'users_model' => env('AUTH_MODEL', 'App\User'),
// Legacy column names (backward compatible)
'created_by_column' => 'created_by',
'updated_by_column' => 'updated_by',
'deleted_by_column' => 'deleted_by',
// Enhanced column configuration
'columns' => [
'created_by' => [
'name' => 'created_by',
'type' => null, // Auto-detect
'nullable' => true,
'index' => true,
'foreign_key' => true,
'on_delete' => 'set null',
'comment' => 'User who created this record'
],
'updated_by' => [
'name' => 'updated_by',
'type' => null,
'nullable' => true,
'index' => true,
'foreign_key' => true,
'on_delete' => 'set null',
'comment' => 'User who last updated this record'
],
'deleted_by' => [
'name' => 'deleted_by',
'type' => null,
'nullable' => true,
'index' => true,
'foreign_key' => true,
'on_delete' => 'set null',
'comment' => 'User who deleted this record'
]
]
];
Supported Column Types
increments- Auto-incrementing integerbigIncrements- Auto-incrementing big integer (default)uuid- UUID stringulid- ULID stringbigInteger- Big integerinteger- Regular integerstring- Variable-length stringtext- Long textchar- Fixed-length string
Testing
Local Testing with Docker
Requirements: Docker, PHP 8.2+, Composer
# Start database containers
docker-compose up -d
# Run all tests (MySQL, PostgreSQL)
composer test:all
# Or test with a specific database
composer test:mysql
composer test:postgres
Test Scripts
The package includes PowerShell and shell scripts for automated testing:
- Windows:
scripts/test-all.ps1 - Linux/macOS:
scripts/test-all.sh
GitHub Actions CI/CD
- Matrix tests for Laravel 12 and PHP 8.4
- Multi-database testing (MySQL and PostgreSQL)
- Code style checking with Laravel Pint
- Security scanning with Composer Audit and CodeQL
Documentation
For detailed information on advanced features:
- Enhanced Configuration - Advanced configuration options and custom column types
- Docker Setup - Complete Docker environment setup
- Docker Setup Summary - Quick Docker setup guide
Docker Setup
The package includes a complete Docker testing environment:
- MySQL 8.0:
127.0.0.1:3306, user:laravel_userstamps, pass:password - PostgreSQL 15:
127.0.0.1:5432, user:laravel_userstamps, pass:password - Redis 7:
127.0.0.1:6379
See DOCKER_README.md for full setup instructions.
Security
- Composer audit and CodeQL scanning in CI
- Dependabot for automated dependency updates
- Regular security vulnerability scanning
Contributing
- Fork the repo
- Create your feature branch (
git checkout -b feature/foo) - Commit your changes
- Push to the branch (
git push origin feature/foo) - Open a pull request
License
MIT © Nur Wachid


