turahe/laravel-userstamps

Adds user tracking fields to Laravel models.

v1.1.1 2025-07-19 18:14 UTC

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, supporting multi-database testing and modern CI/CD.

Features

  • Automatically tracks which user created, updated, or deleted a model
  • Works with Laravel 10, 11, and 12
  • Supports MySQL, PostgreSQL, and SQLite
  • Easy integration with Eloquent models
  • Database schema macros for userstamps
  • Thoroughly tested with GitHub Actions matrix and Docker
  • Code style and security checks included

Installation

composer require turahe/laravel-userstamps

Usage

1. Add the Trait

use Turahe\UserStamps\Concerns\HasUserStamps;

class Post extends Model
{
    use HasUserStamps;
}

2. Migrate Your Table

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

You can publish and customize the config:

php artisan vendor:publish --provider="Turahe\UserStamps\UserStampsServiceProvider" --tag="config"

Testing

Local Testing

Requirements: Docker, PHP 8.2+, Composer

# Start database containers
docker-compose up -d

# Run all tests (SQLite, MySQL, PostgreSQL)
composer test:all

# Or test with a specific database
composer test:mysql
composer test:postgres
composer test        # SQLite (default)

GitHub Actions

  • Matrix tests for Laravel 10/11/12, PHP 8.2/8.3/8.4, and all supported databases
  • Code style checked with Laravel Pint
  • Security scanning with Composer Audit and CodeQL

Docker Setup

See DOCKER_README.md for full details.

  • MySQL: 127.0.0.1:3306, user: laravel_userstamps, pass: password
  • PostgreSQL: 127.0.0.1:5432, user: laravel_userstamps, pass: password

Security

  • Composer audit and CodeQL scanning in CI
  • Dependabot for automated dependency updates

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