2017 © Pedro Peláez
 

laravel-plugin laravel-metadata

Add metadata to laravel models

image

astritzeqiri/laravel-metadata

Add metadata to laravel models

  • Wednesday, August 9, 2017
  • by astritzeqiri
  • Repository
  • 2 Watchers
  • 2 Stars
  • 186 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 11 % Grown

The README.md

Laravel Meta data

Add metadata to laravel models, (*1)

Requirements

  • PHP >=5.4
  • Laravel >= 5.0

Installation

Add laravel-metadata to your composer.json file:, (*2)

"require": {
    "astritzeqiri/laravel-metadata": "~1.0"
}

Get composer to install the package:, (*3)

$ composer require astritzeqiri/laravel-metadata

Registering the Package

Register the service provider within the providers array found in app/config/app.php:, (*4)

'providers' => array(
    // ...
    AstritZeqiri\Metadata\LaravelMetaDataServiceProvider::class
)

If you want you can add an alias to the MetaData model within the aliases array found in app/config/app.php:, (*5)

'aliases' => array(
    // ...
    'MetaData' => AstritZeqiri\Metadata\Models\MetaDada::class,
)

Then you need to publish the migration files:, (*6)

$ php artisan vendor:publish --provider="AstritZeqiri\Metadata\LaravelMetaDataServiceProvider"

And then run the migration:, (*7)

$ php artisan migrate

Usage

Basic Examples

First you need to go to your model and use the HasManyMetaDataTrait:, (*8)

// E.x. User.php
// add this before the class declaration
use AstritZeqiri\Metadata\Traits\HasManyMetaDataTrait;

// after the class declaration add this code snippet:
use HasManyMetaDataTrait;

Updating a meta data entry:

// get the instance
$user = \App\User::first();

// update a metadata if it exists else add a new one
$user->update_meta("meta_key", "meta_value");

Get meta data entry:


// get the instance $user = \App\User::first(); // get a metadata object with a given key $user->get_meta("meta_key"); // if the second parameter is true it returns only the value $user->get_meta("meta_key", true);

Delete meta data entry:


// get the instance $user = \App\User::first(); // delete a metadata entry with a given key $user->delete_meta("meta_key"); // delete all metadatas of a user $user->delete_all_metas();

Filter users by meta_data:



// Search by only one meta data. $users = \App\User::metaQuery('hair_color', 'red')->get(); // filter the users that have red hair color // Search by many meta data. $users = \App\User::metaQuery(array( array('key' => 'hair_color', 'value' => 'red'), array('key' => 'phone_number', 'value' => '%111%', 'compare' => "LIKE") ), "OR")->get(); // filter the users that have red hair color // or that their phone_number contains '111'

License

MIT, (*9)

The Versions

09/08 2017

dev-master

9999999-dev https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

04/03 2017

1.0.8

1.0.8.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

04/03 2017

1.0.7

1.0.7.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

04/03 2017

1.0.6

1.0.6.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

27/02 2017

1.0.5

1.0.5.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

27/02 2017

1.0.4

1.0.4.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

18/11 2016

1.0.3

1.0.3.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

16/11 2016

1.0.2

1.0.2.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

27/07 2016

1.0.1

1.0.1.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

 

laravel meta meta_data

27/07 2016

1.0

1.0.0.0 https://github.com/astritzeqiri/laravel-metadata

Add metadata to laravel models

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

laravel meta meta_data