承接 robertbaelde/laravel_read_only_fields 相关项目开发

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

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

robertbaelde/laravel_read_only_fields

最新稳定版本:1.0.0

Composer 安装命令:

composer require robertbaelde/laravel_read_only_fields

包简介

Protect read only fields from accidentally being updated

README 文档

README

GitHub Tests Action Status

Laravel read only fields lets you guard fields against unexpected updates.

An example use case for this might be when a projector in an event sourced system updates a read model. You want to make sure that the read model only gets updated by the projector.

Guarding fields on a model

To guard fields use the HasReadOnlyFields trait in your model, and specify the read only fields by creating an array on your model named $readOnlyFields

use Illuminate\Database\Eloquent\Model;
use Temperworks\ReadOnlyFields\HasReadOnlyFields;

class YourModel extends Model
{
    use HasReadOnlyFields;

    protected array $readOnlyFields = [
        'read_only_field'
    ];
}

Updating read only fields

When you want to update a read only field, you can mark that you intend to update the field by using writable(['read_only_field']). After the model is saved, the writable state is reset.

$model = YourModel::find(1);
$model->writable(['read_only_field'])->update(['read_only_field' => 'foo']);

// this will throw an exception since we already updated the model. 
$model->update(['read_only_field' => 'foobar']);

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固