Skip to content

paulhenri-l/laravel-has-meta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages