定制 repat/immutability 二次开发

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

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

repat/immutability

Composer 安装命令:

composer require repat/immutability

包简介

A simple Laravel package based on davidmpeace/immutability that allows you to enforce immutable attributes on Eloquent models.

README 文档

README

repat/immutability is a simple package based on davidmpeace/immutability that is used in your Eloquent models to enforce attribute immutability. Immutable attributes may be only set if they are != null, but once the model is saved, the value can not be changed.

License

Immutability is open-sourced software licensed under the MIT license

Installation

To get started with Immutability, add to your composer.json file as a dependency:

$ composer require davidmpeace/immutability

Basic Usage

To use the Immutability library, you simply need to use the Immutability trait for any model you wish to identify immutable attributes for. Typically, you would want to implement the trait in your super-class so that all your sub-classes will automatically inherit the functionality.

<?php
namespace App;

use Illuminate\Database\Eloquent\Model;
use Eloquent\Attributes\Immutability;

class MyAppSuperModel extends Model
{
    use Immutability;

    protected $immutable = ['id', 'uuid'];
}

Class override.

<?php
namespace App;

class User extends MyAppSuperModel
{
    protected $immutable = ['id', 'uuid', 'username'];
}

Catching exceptions

<?php
namespace App;

use Eloquent\Attributes\Exceptions\ImmutableFieldViolationException;
use Exception;

$user = User::find(1);

try {
    $user->username = "myNewUserName";
    $user->save();
} catch ( ImmutableFieldViolationException $e ) {
   // Handle immutable attribute violation error
} catch ( Exception $e ) {
   // Handle error
}

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固