承接 sansanlabs/laravel-userstamps 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

sansanlabs/laravel-userstamps

最新稳定版本:v6.2.1

Composer 安装命令:

composer require sansanlabs/laravel-userstamps

包简介

Package to add userstamps to models.

README 文档

README

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:

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' => \App\Models\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.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-24