paulhenri-l / laravel-has-meta
laravel-has-meta
1.0.0
2021-10-12 21:24 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- orchestra/testbench: ^6.21
- paulhenri-l/php-cs-config: ^1.0
- phpunit/phpunit: ^9.0
- symfony/var-dumper: ^5.3
README
This package make it possible to manage a json meta column using dot notation.
Installation
composer require paulhenri-l/laravel-has-meta
Usage
In your migrations add a meta
column with a type of json
Schema::create('users', function ($table) { $table->bigIncrements('id'); $table->json('meta'); $table->timestamps(); });
Now inside your model use the HasMeta
trait.
<?php namespace PaulhenriL\LaravelHasMeta\Tests\Fakes; use Illuminate\Database\Eloquent\Model; class User extends Model { use \PaulhenriL\LaravelHasMeta\HasMeta; }
You can now use the meta API. The get and set methods use the dot notation in order to get and set values in nested arrays.
The encrypted methods uses the Crypt
facade and will therefore use your app's
encryption settings.
$user = new User(); // Set $user->setMeta('preferences.time_zone', 'Europe/Paris'); $user->setEncryptedMeta('health.has_diabet', true); // Get $user->getMeta('preferences.time_zone'); $user->getEncryptedMeta('health.has_diabet');