sansanlabs/laravel-userstamps

Package to add userstamps to models.
1,281 2
Install
composer require sansanlabs/laravel-userstamps
Latest Version:v8.2.0
PHP:^8.3
Laravel:11 · 12 · 13
Older releases:10
License:MIT
Last Updated:Jun 22, 2026
Links: GitHub  ·  Packagist
Maintainer: sansanlabs

Laravel Userstamps

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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:

<?php

use App\Models\User;

return [
    /*
    | If set to true, the package will generate polymorphic relations
    | with an additional "_type" column.
    |
    | ⚠️ Warning:
    | Please make sure to enable or disable this BEFORE running migrations,
    | as it affects how your relationship columns are generated.
    |
    */
    'is_using_morph' => false,

    /*
    | The name of the table that holds the users.
    |
    | ⚠️ Note:
    | This configuration is used **only when "is_using_morph" is false**.
    | If "is_using_morph" is set to true, this value will be ignored
    | because the relationship will use polymorphic "_type" columns instead
    | of a fixed user table reference.
    |
    */
    'users_table' => 'users',

    /*
    | The model that holds the users.
    |
    | ⚠️ Note:
    | This configuration is used **only when "is_using_morph" is false**.
    | If "is_using_morph" is set to true, this value will be ignored
    | because the morph relationship dynamically references the related model
    | based on the stored "_type" column.
    |
    */
    'users_model' => User::class,

    /*
    | 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',

    /*
    | If you set the column name to "created_by",
    | it will generate two columns:
    | - created_by_id
    | - created_by_type (if morph is enabled)
    */
    'created_by_column' => 'created_by',

    /*
    | If you set the column name to "updated_by",
    | it will generate two columns:
    | - updated_by_id
    | - updated_by_type (if morph is enabled)
    |
    */
    'updated_by_column' => 'updated_by',

    /*
    | If you set the column name to "deleted_by",
    | it will generate two columns:
    | - deleted_by_id
    | - deleted_by_type (if morph is enabled)
    |
    */
    '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->createdBy; // the user who created the model
$model->updatedBy; // the user who last updated the model
$model->deletedBy; // 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.

Related Packages

wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `cre...

2,181,467 753
jlorente/laravel-identitystamps

A Laravel plugin to register and keep control of the users who make creations, u...

6,234 1
rulr/laravel-authored

A Laravel package that adds created_by and last_updated_by attributes to Eloquen...

1,934 4
spatie/laravel-sluggable

Generate slugs when saving Eloquent models

14,952,324 1,558
hootlex/laravel-friendships

This package gives Eloquent models the ability to manage their friendships.

129,297 697

Version History

Version Released PHP Laravel License
v8.2.0 ^8.3 ^11.0 || ^12.0 || ^13.0 MIT
v8.1.0 ^8.3 ^11.0 || ^12.0 || ^13.0 MIT
v8.0.0 ^8.3 ^11.0 || ^12.0 || ^13.0 MIT
v7.1.0 ^8.3 ^11.0 || ^12.0 || ^13.0 MIT
v7.0.0 ^8.3 ^11.0 || ^12.0 || ^13.0 MIT