承接 laragrad/eloquent-model-userstamps 相关项目开发

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

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

laragrad/eloquent-model-userstamps

Composer 安装命令:

composer require laragrad/eloquent-model-userstamps

包简介

README 文档

README

This package provides a trait for Model to fill userstamp fields.

Installing

Run command in console

composer require laragrad/eloquent-model-userstamps

Using

Preparing table

Add into your model's table migration userstamp fields. It's type must be same as type of user id. You can use default created_by, updated_by, deleted_by field names or any other.

You can use Laragrad\Support\Userstamps methods addUserstampColumns() to add or dropUserstampColumns() drop columns in your migration file.

For example, to add userstamps columns:

<?php

use ...;
use Laragrad\Support\Userstamps as UserstampsSupport; // Add use

class CreateExampleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('examples', function (Blueprint $table) {
            
            $table->id('id');
            ...
            UserstampsSupport::addUserstampsColumns($table); // Creating columns

        });
    }

    ...
}

If you use soft deleting in your table then put true into 2nd argument. To change type of your userstamps columns you can put 'uuid' or 'integer' or 'bigInteger' into 3rd argument. By default created columns has default names. If your userstamp columns have not default names then put column name array into 4th argument.

For example:

UserstampsSupport::addUserstampsColumns($table, true, 'uuid', ['create_user_id','update_user_id','deleted_user_id']);

To drop columns you can use UserstampsSupport::dropUserstampsColumns(). For example

UserstampsSupport::dropUserstampsColumns($table, true, ['create_user_id','update_user_id','deleted_user_id']);

Preparing model

Add next changes into your table model class:

  • add use trait \Laragrad\Models\Concerns\HasUserstamps into your model class;

  • add property public $userstamps = true;

    use Laragrad\Models\Concerns\HasUserstamps; // (1)

    class YourModel extends Model { use HasUserstamps; // (2)

    public $userstamps = true;					 // (3)
    
    ...
    

    }

The created_by and updated_by fields in your model will now be populated in the same way as the timestamp fields when you create or update the model. If your model uses SoftDeletes trait, will also be processed field, deleted_by.

Using custom userstamp field names

If your table userstamp field names are not defaults then declare next constants in your model:

class YourModel extends Model
{
	...
	
	const CREATED_BY = 'your_created_by_field_name'; 
	const UPDATED_BY = 'your_updated_by_field_name'; 
	const DELETED_BY = 'your_deleted_by_field_name'; 
	
	...
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-06-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固