定制 brainstud/has-identifier 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

brainstud/has-identifier

最新稳定版本:v2.1.0

Composer 安装命令:

composer require brainstud/has-identifier

包简介

Add a HasIdentifier to the model to take care of generating the identifier

README 文档

README

Automatically fill the identifier of your model by adding the HasIdentifier trait.

Installation

Require the package

composer require brainstud/has-identifier

Usage

Add the HasIdentifier trait to your model.

/**
 * @property string $identifier
 */
class Item extends Model
{
    use HasIdentifier;
    
    protected $fillable = [
        'identifier'
    ];
}

The identifier will be filled on creation.

$model = Item::create();
echo $model->identifier;

Use a different identifier attribute

The trait will use the identifier property of your model to generate an identifier to. You can overwrite the property the trait uses by setting the identifierAttribute on your model.

/**
 * @property string $identifier
 */
class Item extends Model
{
    use HasIdentifier;
    
    protected string $identifierAttribute = 'uuid';
    
    protected $fillable = [
        'uuid'
    ];
}

Find by identifier

There are different ways to get the model by identifier.

// Find method
$model = Item::findByIdentifier($uuid);
$model = Item::findOrFailByIdentifier($uuid);

// Scope
$model = Item::identifiedBy($uuid)->first();

Test

You can run the tests with

composer test

License

has-identifier is open-sourced software licensed under the MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-03-30