turahe/laravel-userstamps
Composer 安装命令:
composer require turahe/laravel-userstamps
包简介
Adds user tracking fields to Laravel models.
README 文档
README
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
turahe/laravel-userstamps 适用场景与选型建议
turahe/laravel-userstamps 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 287 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「updated」 「created」 「userstamps」 「deleted」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 turahe/laravel-userstamps 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 turahe/laravel-userstamps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 turahe/laravel-userstamps 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Package to add created_by, updated_by and deleted_by to models.
Tracks the user responsible for creating, modifying, or deleting an Eloquent model
Alfabank REST API integration
This module allows you to add a list of values to the CMS Fields for a record based around the casting (casted) methods / variables so that you get more information abohe record
Automatically track which user created and last updated your Eloquent models, with relations and schema macros.
Record which Member created or last edited a DataObject
统计信息
- 总下载量: 287
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-10