Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Userstamps Laravel Package

sansanlabs/laravel-userstamps

View on GitHub
Deep Wiki
Context7

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo