andreadam82 / laravel-userstamps

用于向模型添加 created_by, updated_by 和 deleted_by 的包。

0.0.11 2022-09-14 13:56 UTC

This package is auto-updated.

Last update: 2024-09-16 20:07:06 UTC


README

提供了一个 Eloquent 特性,可以自动在您的模型上维护 created_by、updated_by 和 deleted_by(当使用 softDeletes 时),由当前登录的用户执行。

Latest Version on Packagist StyleCI Total Downloads

安装和使用

此包需要 PHP 7.2 和 Laravel 5.6 或更高版本。通过在您的控制台中运行以下命令来安装此包:

composer require andreadam82/laravel-userstamps

您可以使用以下命令发布配置文件:

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

这是已发布配置文件的内容

return [

    /*
     * Define the table which is used in the database to retrieve the users
     */

    'users_table' => 'users',
    
    /*
     * Define the table column type which is used in the table schema for
     * the id of the user
     *
     * Options: increments, bigIncrements, uuid
     * Default: bigIncrements
     */

    'users_table_column_type' => 'bigIncrements',

    /*
     * Define the name of the column which is used in the foreign key reference
     * to the id of the user
     */

    'users_table_column_id_name' => 'id',
    
    /*
     * Define the mmodel which is used for the relationships on your models
     */
    
    'users_model' => \App\Models\User::class,
    
    /*
     * Define the column which is used in the database to save the user's id
     * which created the model.
     */

    'created_by_column' => 'created_by',

    /*
     * Define the column which is used in the database to save the user's id
     * which updated the model.
     */

    'updated_by_column' => 'updated_by',

    /*
     * Define the column which is used in the database to save the user's id
     * which deleted the model.
     */

    'deleted_by_column' => 'deleted_by',

];

将宏添加到您的模型迁移中

public function up()
{
    Schema::create('table_name', function (Blueprint $table) {
        ...

        $table->userstamps();
        $table->softUserstamps();
    });
}   

将特性添加到您的模型中

use Sqits\UserStamps\Concerns\HasUserStamps;

class Example extends Model {

    use HasUserStamps;
}

将提供方法以检索执行创建、更新或删除操作的用户对象

$model->author; // the user who created the model
$model->editor; // the user who last updated the model
$model->destroyer; // the user who deleted the model

变更日志

请参阅 CHANGELOG 了解最近有哪些更改。

安全

如果您发现任何安全相关的问题,请通过电子邮件 info@sqits.nl 与我们联系,而不是使用问题跟踪器。

致谢

许可

MIT 许可证(MIT)。请参阅 许可文件 了解更多信息。