LaravelPackages.net
Acme Inc.
Toggle sidebar
paulhenri-l/laravel-has-meta

laravel-has-meta

162
0
1.0.0
About paulhenri-l/laravel-has-meta

paulhenri-l/laravel-has-meta is a Laravel package for laravel-has-meta. It currently has 0 GitHub stars and 162 downloads on Packagist (latest version 1.0.0). Install it with composer require paulhenri-l/laravel-has-meta. Discover more Laravel packages by paulhenri-l or browse all Laravel packages to compare alternatives.

Last updated

LaravelHasMeta

PHP Tests PHP Code Style License: MIT

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');

Star History Chart