turahe/laravel-userstamps 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

turahe/laravel-userstamps

Composer 安装命令:

composer require turahe/laravel-userstamps

包简介

Adds user tracking fields to Laravel models.

README 文档

README

CI Security codecov Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License PHP Version Laravel Version StyleCI Scrutinizer Code Quality Code Coverage Build Status Dependabot Status Maintenance Made with Love

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 integer
  • bigIncrements - Auto-incrementing big integer (default)
  • uuid - UUID string
  • ulid - ULID string
  • bigInteger - Big integer
  • integer - Regular integer
  • string - Variable-length string
  • text - Long text
  • char - 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:

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

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/foo)
  3. Commit your changes
  4. Push to the branch (git push origin feature/foo)
  5. 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 turahe/laravel-userstamps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 287
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 18
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-10