faustbrian/laravel-arbitrary-attributes

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Character Avatar Builder for Laravel

1.0.1 2021-10-13 09:31 UTC

This package is auto-updated.

Last update: 2021-11-14 04:22:05 UTC


README

You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.

Arbitrary Attributes for Laravel Eloquent

PHP Latest Version

Installation

composer require faustbrian/laravel-arbitrary-attributes

Usage

Model

<?php

use Faust\ArbitraryAttributes\HasArbitraryAttributes;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use HasArbitraryAttributes;
}

Attributes

$user = User::create([ ... ]);

// Get the value of "key"
$user->getArbitraryAttributes()->get('key');

// Set the "key" value to "value"
$user->getArbitraryAttributes()->set('key', 'value');

// Forget the value of "key"
$user->getArbitraryAttributes()->forget('key');

// Count how many keys there are
$user->getArbitraryAttributes()->count();

// Commit any changes to the database.
$user->getArbitraryAttributes()->commit();

Testing

composer test

License

This is an open-sourced software licensed under the AGPL-3.0-or-later.