larapack / attribute-purging by emptynick

Allows you to define what attributes in your Eloquent Model which should be not be inserted into the database.
159
4
4
Package Data
Maintainer Username: emptynick
Package Create Date: 2015-11-27
Package Last Update: 2018-06-08
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2021-10-12 03:14:38
Package Statistics
Total Downloads: 159
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 4
Total Watchers: 4
Total Forks: 2
Total Open Issues: 0

attribute-purging

Allows you to define what attributes in your Eloquent Model which should be not be inserted into the database.

Installing

Install using Composer composer require larapack/attribute-purging.

Usage

First add the trait Purgeable to your Eloquent Model.

<?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
  
  //...
}

Test:

$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.