2017 © Pedro Peláez
 

library immutability

A simple Laravel package that allows you to enforce immutable attributes on Eloquent models.

image

davidmpeace/immutability

A simple Laravel package that allows you to enforce immutable attributes on Eloquent models.

  • Friday, April 22, 2016
  • by davidmpeace
  • Repository
  • 1 Watchers
  • 2 Stars
  • 6,527 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 7 % Grown

The README.md

Immutability

Immutability is a simple package that is used in your Eloquent models to enforce attribute immutability. Immutable attributes may be set, and changed once, but once the model is saved, the value can not be changed., (*1)

License

Immutability is open-sourced software licensed under the MIT license, (*2)

Installation

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

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., (*4)

<?php
namespace App;

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

class MyAppSuperModel extends Model
{
    use Immutability;

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

Class override., (*5)

<?php
namespace App;

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

Catching exceptions, (*6)

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

The Versions

22/04 2016

dev-master

9999999-dev

A simple Laravel package that allows you to enforce immutable attributes on Eloquent models.

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Peace

orm laravel eloquent attributes immutable automatic

22/04 2016

0.2

0.2.0.0

A simple Laravel package that allows you to enforce immutable attributes on Eloquent models.

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Peace

orm laravel eloquent attributes immutable automatic

22/04 2016

0.1

0.1.0.0

A simple Laravel package that allows you to enforce immutable attributes on Eloquent models.

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Peace

orm laravel eloquent attributes immutable automatic