larapack/attribute-purging

此包已被弃用且不再维护。未建议替代包。

允许您定义在Eloquent模型中哪些属性不应插入到数据库中。

v1.0.1 2018-06-08 11:36 UTC

This package is auto-updated.

Last update: 2022-10-06 05:03:23 UTC


README

允许您定义在Eloquent模型中哪些属性不应插入到数据库中。

安装

使用Composer安装 composer require larapack/attribute-purging

使用方法

首先将特质 Purgeable 添加到您的Eloquent模型中。

<?php

namespace App;

use Larapack\AttributePurging\Purgeable;

class User
{
  use Purgeable;
  
  /**
   * @var array List of attribute names which should be purged
   */ 
  protected $purge = ['foo']; // set the attribute names you which to purge
  
  //...
}

测试

$user = new App\User;
$user->foo = 'bar';
$user->save(); // The attribute 'foo' will not be saved to the database.
echo $user->foo; // Will still returns 'bar' as long you hold the same instance of the object.