Laravel 5+ 的只读模型

v1.0.0 2024-06-18 16:47 UTC

This package is auto-updated.

Last update: 2024-09-18 17:22:31 UTC


README

Total Downloads build workflow Latest Version on Packagist

Laravel 5+ 只读模型

只读特性移除了保存、删除或修改 Laravel 模型的能力。理想情况下,这应该与数据库权限结合使用,以确保用户和开发者无法写入旧系统。

安装

composer require michaelachrisco/readonly

使用方法

<?php
use Illuminate\Database\Eloquent\Model;
use MichaelAChrisco\ReadOnly\ReadOnlyTrait;
class User extends Model {
  use ReadOnlyTrait;
}

$legacyUser = new User;
$legacyUser->set_user_name('bob');

$result = $legacyUser->save();
//User is not saved. 
//ReadOnlyException is thrown.
 ?>

会抛出ReadOnlyExceptions异常的方法

  • create
  • forceCreate
  • save
  • update
  • firstOrCreate
  • firstOrNew
  • delete
  • destroy
  • restore
  • forceDelete
  • performDeleteOnModel
  • push
  • finishSave
  • performUpdate
  • touch
  • insert
  • truncate
  • 请为发现的任何其他方法提交PR!