2017 © Pedro Peláez
 

library eloquent-array

A Laravel package to deal with array values that we can search through where clause.

image

sukohi/eloquent-array

A Laravel package to deal with array values that we can search through where clause.

  • Tuesday, January 31, 2017
  • by Sukohi
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

EloquentArray

A Laravel package to deal with array values that we can search through where clause.
This package is only for Laravel 5.3+., (*1)

Installation

Execute the following command., (*2)

composer require sukohi/eloquent-array:6.*

then set EloquentArrayServiceProvider in your config/app.php., (*3)

Sukohi\EloquentArray\EloquentArrayServiceProvider::class, 

Preparation

Execute the following command to publish and migrate the migration., (*4)

php artisan vendor:publish --provider="Sukohi\EloquentArray\EloquentArrayServiceProvider"
php artisan migrate

Then set EloquentArrayTrait in your model like so., (*5)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Sukohi\EloquentArray\EloquentArrayTrait;

class Item extends Model
{
    use EloquentArrayTrait;
}

Usage

Set

$item = \App\Item::find(1);
$item->setArray('locales', [
    'en' => 'English',
    'es' => 'Spanish',
    'ja' => 'Japanese'
]);
$item->saveArray();

Unset

$item->unsetArray('locales'); // Remove `locales`
$item->saveArray();

// Or

$item->unsetArray('locales', 'en'); // Remove `en`
$item->saveArray();

Delete

A specific array values related to an item will be removed., (*6)

\App\Item::find(1)->deleteArray('locales');

Clear

All of the array values related to an item will be removed., (*7)

\App\Item::find(1)->clearArray();

Retrieve

with Key, (*8)

$item = \App\Item::find(1);
$array = $item->getArray('locales');

/* 

    Array
    (
        [en] => English
        [es] => Spanish
        [ja] => Japanese
    )

*/

without Key, (*9)

$array = $item->getArray('locales', false);

/* 

    Array
    (
        [0] => English
        [1] => Spanish
        [2] => Japanese
    )

*/

All values, (*10)

$array = $item->getAllArray();

A Specific Value, (*11)

echo $item->getArrayValue('locales', 'en'); // English

// with Default Value

echo $item->getArrayValue('locales', 'en', 'Default-Value');

Where Clause

You can use whereArray() method to filter your data like so., (*12)

$items = \App\Item::whereArray('locales', 'en')->get();

// or

$items = \App\Item::where('id', 1)
    ->orWhereArray('locales', 'en')
    ->get();

Order by Clause

You can use array items name for ORDER BY like so., (*13)

$items = \App\Item::orderByArray('names', 'en')->get();         // asc
$items = \App\Item::orderByArray('names', 'en', 'asc')->get();

// or

$items = \App\Item::orderByArray('names', 'en', 'desc')->get();

Model

[Set], (*14)

$item->setModelArray('App\User', 1);   // Model ID
$item->saveArray();

[Set Array], (*15)

$item->setAllModelArray([
    'App\User' => [1, 2, 3, 4, 5]   // Model IDs
]);
$item->saveArray();

[Unset], (*16)

$item->unsetModelArray([
    'App\User' => [2, 3]   // Model IDs
]);
$item->saveArray();

[Clear], (*17)

$item->clearModelArray('App\User');
$item->saveArray();

// or

$item->clearModelArray([
    'App\User',
    'App\Item'
]);
$item->saveArray();

[Retrieve], (*18)

$users = $item->getModelArray('App\User');

License

This package is licensed under the MIT License.
Copyright 2016 Sukohi Kuhoh, (*19)

The Versions

31/01 2017

6.0.x-dev

6.0.9999999.9999999-dev

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

31/01 2017

dev-master

9999999-dev

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

31/01 2017

6.0.0

6.0.0.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

18/10 2016

5.0.x-dev

5.0.9999999.9999999-dev

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

18/10 2016

5.0.1

5.0.1.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

18/10 2016

5.0.0

5.0.0.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

18/10 2016

4.0.x-dev

4.0.9999999.9999999-dev

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

18/10 2016

4.0.9

4.0.9.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

05/10 2016

4.0.8

4.0.8.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

05/10 2016

4.0.7

4.0.7.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

27/09 2016

4.0.6

4.0.6.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

27/09 2016

4.0.5

4.0.5.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

27/09 2016

4.0.4

4.0.4.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

01/09 2016

4.0.3

4.0.3.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

19/08 2016

4.0.2

4.0.2.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

10/08 2016

4.0.1

4.0.1.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

10/08 2016

4.0.0

4.0.0.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

09/08 2016

3.0.x-dev

3.0.9999999.9999999-dev

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

09/08 2016

3.0.0

3.0.0.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

06/06 2016

2.0.x-dev

2.0.9999999.9999999-dev

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

06/06 2016

2.0.0

2.0.0.0

A Laravel package to deal with array values that we can search through where clause.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi