sukohi/eloquent-array
Larablocks Analysis
sukohi/eloquent-array works with Laravel 5 (latest release 6.0.0, Jan 31, 2017), which reached end of life: no more fixes, even for security.
Recommendation checks
Not advisedNot advised: no release or commit in over 2 years.
- No release or commit in over 2 years
- Supports only Laravel 5, past end of life
- No release in the last 12 months (last: Jan 31, 2017)
- 0 downloads a month (needs 10,000)
- 0 GitHub stars (needs 100)
State
Likely abandoned- No release or commit in over 2 years.
- Last stable release: Jan 31, 2017.
- No releases in the last 12 months.
- First released: Jun 6, 2016.
- 0 open issues on GitHub.
Data from Packagist and GitHub, checked by Larablocks on Nov 27, 2026.
| Install | |
|---|---|
composer require sukohi/eloquent-array |
|
| Latest Version: | 6.0.0 |
| Laravel: | 5 |
| License: | MIT |
| Last Updated: | Jan 31, 2017 |
| Links: | GitHub · Packagist |
EloquentArray
A Laravel package to deal with array values that we can search through where clause.
This package is only for Laravel 5.3+.
Installation
Execute the following command.
composer require sukohi/eloquent-array:6.*
then set EloquentArrayServiceProvider in your config/app.php.
Sukohi\EloquentArray\EloquentArrayServiceProvider::class,
Preparation
Execute the following command to publish and migrate the migration.
php artisan vendor:publish --provider="Sukohi\EloquentArray\EloquentArrayServiceProvider"
php artisan migrate
Then set EloquentArrayTrait in your model like so.
<?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.
\App\Item::find(1)->deleteArray('locales');
Clear
All of the array values related to an item will be removed.
\App\Item::find(1)->clearArray();
Retrieve
with Key
$item = \App\Item::find(1);
$array = $item->getArray('locales');
/*
Array
(
[en] => English
[es] => Spanish
[ja] => Japanese
)
*/
without Key
$array = $item->getArray('locales', false);
/*
Array
(
[0] => English
[1] => Spanish
[2] => Japanese
)
*/
All values
$array = $item->getAllArray();
A Specific Value
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.
$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.
$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]
$item->setModelArray('App\User', 1); // Model ID
$item->saveArray();
[Set Array]
$item->setAllModelArray([
'App\User' => [1, 2, 3, 4, 5] // Model IDs
]);
$item->saveArray();
[Unset]
$item->unsetModelArray([
'App\User' => [2, 3] // Model IDs
]);
$item->saveArray();
[Clear]
$item->clearModelArray('App\User');
$item->saveArray();
// or
$item->clearModelArray([
'App\User',
'App\Item'
]);
$item->saveArray();
[Retrieve]
$users = $item->getModelArray('App\User');
License
This package is licensed under the MIT License.
Copyright 2016 Sukohi Kuhoh
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | Laravel | License |
|---|---|---|---|
| 6.0.0 | ~5.2 | MIT | |
| 5.0.1 | ~5.2 | MIT | |
| 5.0.0 | ~5.2 | MIT | |
| 4.0.9 | ~5.2 | MIT | |
| 4.0.8 | ~5.2 | MIT | |
| 4.0.7 | ~5.2 | MIT | |
| 4.0.6 | ~5.2 | MIT | |
| 4.0.5 | ~5.2 | MIT | |
| 4.0.4 | ~5.2 | MIT | |
| 4.0.3 | ~5.2 | MIT | |
| 4.0.2 | ~5.2 | MIT | |
| 4.0.1 | ~5.2 | MIT | |
| 4.0.0 | ~5.2 | MIT | |
| 3.0.0 | ~5.2 | MIT | |
| 2.0.0 | ~5.0 | MIT |