PHPackages                             longman/laravel-lodash - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. longman/laravel-lodash

ActiveLibrary[Caching](/categories/caching)

longman/laravel-lodash
======================

Add more functional to Laravel

12.1.0(1y ago)9792.9k↓37.9%11[2 PRs](https://github.com/akalongman/laravel-lodash/pulls)MITPHPPHP ^8.2CI failing

Since Oct 7Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/akalongman/laravel-lodash)[ Packagist](https://packagist.org/packages/longman/laravel-lodash)[ Docs](https://github.com/akalongman/laravel-lodash)[ RSS](/packages/longman-laravel-lodash/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (11)Versions (117)Used By (0)

Laravel Lodash
==============

[](#laravel-lodash)

[![Build Status](https://camo.githubusercontent.com/4bb4080f85157b8a36c23786f1755831879d650e570248d107e7c581ade31871/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f616b616c6f6e676d616e2f6c61726176656c2d6c6f646173682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/akalongman/laravel-lodash)[![Code Coverage](https://camo.githubusercontent.com/b1da72891f2945c48f99c22775bed368992f555b4c438b075b1ddb0845f20881/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f616b616c6f6e676d616e2f6c61726176656c2d6c6f646173682e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/akalongman/laravel-lodash/?branch=master)[![Code Quality](https://camo.githubusercontent.com/11aa01185eb2c2d6ddac686932b90fc8781fe33ad237de01001a18d649fc0166/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f616b616c6f6e676d616e2f6c61726176656c2d6c6f646173682e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/akalongman/laravel-lodash/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/9fb39a1cbec61bf1b406307570af09ea287a17d3c4e9d042db6b01b3330ea745/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f616b616c6f6e676d616e2f6c61726176656c2d6c6f646173682e7376673f7374796c653d666c61742d737175617265)](https://github.com/akalongman/laravel-lodash/tags)[![Total Downloads](https://camo.githubusercontent.com/78f5cf307a0b5090aa528cf8bb08a53b156fba0ad10a468acffc9022952c45a7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4c6f6e676d616e2f6c61726176656c2d6c6f646173682e737667)](https://packagist.org/packages/longman/laravel-lodash)[![Downloads Month](https://camo.githubusercontent.com/fcab41108043c29a3753db68f40e394608103f80c891d84006df06438ff04713/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f4c6f6e676d616e2f6c61726176656c2d6c6f646173682e737667)](https://packagist.org/packages/longman/laravel-lodash)[![License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

This package adds lot of useful functionality to the Laravel &gt;=8.0 project

**Note:** For Laravel older than 5.8 use the package version 1.*, for older than 8.0 - version 4.*

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [General](#general)
        - [Enable Debug Mode depending on visitor's IP Address](#enable-debug-mode-depending-on-visitors-ip-address)
        - [Add created\_by, updated\_by and deleted\_by to the eloquent models](#add-created_by-updated_by-and-deleted_by-to-the-eloquent-models)
        - [Use UUID in the Eloquent Models](#use-uuid-in-the-eloquent-models)
        - [Eager loading of limited many to many relations via subquery or union](#eager-loading-of-limited-many-to-many-relations-via-subquery-or-union)
        - [Redis using igbinary](#redis-using-igbinary)
        - [Redis client side sharding](#redis-client-side-sharding)
        - [AWS SQS Fifo Queue](#aws-sqs-fifo-queue)
        - [Elasticsearch Integration](#elasticsearch-integration)
        - [Check if installed packages are in sync with composer.lock](#check-if-installed-packages-are-in-sync-with-composer.lock)
    - [Helper Functions](#helper-functions)
    - [Extended Classes](#extended-classes)
        - [Request Class](#request-class)
    - [Artisan Commands](#artisan-commands)
    - [Middleware List](#middleware-list)
        - [XssSecurity](#xsssecurity)
        - [SimpleBasicAuth](#simplebasicauth)
    - [Blade Directives](#blade-directives)
    - [Misc](#misc)
        - [SelfDiagnosis Checks](#selfdiagnosis-checks)
- [TODO](#todo)
- [Troubleshooting](#troubleshooting)
- [Contributing](#contributing)
- [License](#license)
- [Credits](#credits)

Installation
------------

[](#installation)

Install this package through [Composer](https://getcomposer.org/).

Run a command in your command line:

```
composer require longman/laravel-lodash

```

Add `LodashServiceProvider` to your service providers list in the `app.php`

```
'providers' => [
    . . .
    /*
     * Package Service Providers...
     */
    Longman\LaravelLodash\ServiceProvider::class,
    . . .
],
```

Copy the package config and translations to your application with the publish command:

```
php artisan vendor:publish --provider="Longman\LaravelLodash\LodashServiceProvider"

```

Usage
-----

[](#usage)

### General

[](#general)

#### Enable Debug Mode depending on visitor's IP Address

[](#enable-debug-mode-depending-on-visitors-ip-address)

Add `Longman\LaravelLodash\Debug\DebugServiceProvider::class` in to `config/app.php`and specify debug IP's in your `config/lodash.php` config file:

```
    . . .
    'debug' => [
        'ips' => [ // IP list for enabling debug mode
            //'127.0.0.1',
        ],
    ],
    . . .
```

#### Add created\_by, updated\_by and deleted\_by to the eloquent models

[](#add-created_by-updated_by-and-deleted_by-to-the-eloquent-models)

Sometimes we need to know who created, updated or deleted entry in the database.

For this just add `Longman\LaravelLodash\Eloquent\UserIdentities` trait to your model and also update migration file adding necessary columns:

```
    $table->unsignedInteger('created_by')->nullable();
    $table->unsignedInteger('updated_by')->nullable();
    $table->unsignedInteger('deleted_by')->nullable();
```

#### Use UUID in the Eloquent Models

[](#use-uuid-in-the-eloquent-models)

For this just add `Longman\LaravelLodash\Eloquent\UuidAsPrimary` trait to your model and also update related migration file:

```
    $table->uuid('id')->primary();
```

Also there is possible to specify uuid version via defining `uuidVersion` property in the model class.

#### Eager loading of limited many to many relations via subquery or union

[](#eager-loading-of-limited-many-to-many-relations-via-subquery-or-union)

Eager load many to many relations with limit via subquery or union. For using this feature, add `Longman\LaravelLodash\Eloquent\ManyToManyPreload` trait to the models. After that you can use methods `limitPerGroupViaUnion()` and `limitPerGroupViaSubQuery()`. For example you want to select users and 3 related user photos per user.

```
    $items = (new User)->with([
        'photos' => function (BelongsToMany $builder) {
            // Select via union. There you should pass pivot table fields array
            $builder->limitPerGroupViaUnion(3, ['user_id', 'photo_id']);
            // or
            // Select via subquery
            $builder->limitPerGroupViaSubQuery(3);
        }, 'other.relation1', 'other.relation2'
    ]);
    $items = $items->get();
```

Now each user model have 3 photos model selected via one query. You can specify additional where clauses or order by fields before the group method call.

#### Redis using igbinary

[](#redis-using-igbinary)

Igbinary is a drop in replacement for the standard php serializer. Igbinary stores php data structures in compact binary form. Savings are significant when using Redis or similar memory based storages for serialized data. Via Igbinary repetitive strings are stored only once. Collections of Eloquent objects benefit significantly from this.

By default Laravel does not provide an option to enable igbinary serializer for PhpRedis connection and you have to use LaravelLodash implementation for this.

First of all, make sure you enabled PhpRedis driver by this guide

After that include Cache and Redis service providers in the `app.php` before your App providers:

```
    . . .
    Longman\LaravelLodash\Cache\CacheServiceProvider::class,
    Longman\LaravelLodash\Redis\RedisServiceProvider::class,
    . . .
```

You can remove Laravel's Cache and Redis service providers from the config, because LaravelLodash providers are extended from them and therefore implements entire functional.

Now you can specify the serializer in your `database.php` under `config` folder:

Also, you can specify other options like `scan` or etc. See

#### Redis client side sharding

[](#redis-client-side-sharding)

PhpRedis extension along with native Redis Cluster, also supports [client-side sharding](https://github.com/phpredis/phpredis/blob/develop/arrays.markdown#readme). This feature is very useful, when you want distribute your data between multiple servers, but do not want use native Redis Cluster.

Its not implemented in the Laravel by default. We tried to fix this 😄

Config example:

```
    . . .
    'redis' => [
        'client' => 'phpredis',

        'clusters' => [
            'options' => [
                'lazy_connect'      => true,
                'connect_timeout'   => 1,
                'read_timeout'      => 3,
                'password'          => env('REDIS_PASSWORD', null),
                'database'          => env('REDIS_DATABASE', 0),
                'prefix'            => env('REDIS_PREFIX'),
                'serializer'        => Redis::SERIALIZER_IGBINARY,
                'compression'       => Redis::COMPRESSION_ZSTD,
                'compression_level' => Redis::COMPRESSION_ZSTD_DEFAULT,
            ],

            'default' => [
                [
                    'host' => env('REDIS_SHARD1_HOST', '127.0.0.1'),
                    'port' => env('REDIS_SHARD1_PORT', 6379),
                ],
                [
                    'host' => env('REDIS_SHARD2_HOST', '127.0.0.2'),
                    'port' => env('REDIS_SHARD2_PORT', 6379),
                ],
                . . .
            ],
        ],
    ],
    . . .
```

#### AWS SQS Fifo Queue

[](#aws-sqs-fifo-queue)

Laravel by default does not supports AWS FIFO queues and this package fixes it.

You have to add `QueueServiceProvider` service provider in the `app.php` before your App providers:

```
    . . .
    Longman\LaravelLodash\Queue\QueueServiceProvider::class,
    . . .
```

You can remove Laravel's Queue service provider from the config, because LaravelLodash provider are extended from that and therefore implements entire functional.

Now you can add the new connection in the `queue.php` under `config` folder:

```
    . . .
    'sqs_fifo' => [
        'driver'  => 'sqs.fifo',
        'version' => 'latest',
        'key'     => env('AWS_ACCESS_KEY_ID'),
        'secret'  => env('AWS_SECRET_ACCESS_KEY'),
        'prefix'  => env('AWS_SQS_URL'),
        'queue'   => env('AWS_SQS_DEFAULT_QUEUE'),
        'region'  => env('AWS_DEFAULT_REGION'),
        'options' => [
            'type'      => 'fifo', // fifo, normal
            'polling'   => 'long', // long, short
            'wait_time' => 20,
        ],
    ],
    . . .
```

#### Elasticsearch Integration

[](#elasticsearch-integration)

First of all you have to install official elasticsearch php sdk:

```
composer require elasticsearch/elasticsearch

```

After add `ElasticsearchServiceProvider` service provider in the `app.php` before your App providers:

```
    . . .
    Longman\LaravelLodash\Elasticsearch\ElasticsearchServiceProvider::class,
    . . .
```

Now you can add the configuration in the `services.php` under `config` folder:

```
    . . .
    'elasticsearch' => [
        'enabled'          => env('ELASTICSEARCH_ENABLED', false),
        'log_channel'      => ['daily'],
        'hosts'            => [
            [
                'host' => env('ELASTICSEARCH_HOST', 'localhost'),
                'port' => env('ELASTICSEARCH_PORT', 9200),
            ],
        ],
        'connectionParams' => [
            'client' => [
                'timeout'         => env('ELASTICSEARCH_TIMEOUT', 3),
                'connect_timeout' => env('ELASTICSEARCH_TIMEOUT', 3),
            ],
        ],
    ],
    . . .
```

You can use Elasticsearch integration via

```
    $elasticsearch_manager = app(ElasticsearchManagerContract::class);

    // Call wrapped methods
    $elasticsearch_manager->createIndex('some-index');

    // Or get native client and access their methods
    $client = $elasticsearch_manager->getClient();
    $client->indices()->create($params);
```

Also you can perform search via searchable query object. Just create class and implement `ElasticsearchQueryContract` and you can pass object to `performSearch` method

```
    $elasticsearch_manager = app(ElasticsearchManagerContract::class);
    $results = $elasticsearch_manager->performSearch($query);
```

Check if installed packages are in sync with composer.lock
----------------------------------------------------------

[](#check-if-installed-packages-are-in-sync-with-composerlock)

For development purposes, it is recommended to check if vendor folder is in sync with composer.lock file.

For this, in composer.json you have to add script `ComposerScripts::createPackageHash`:

```
    . . .
    "post-autoload-dump": [
        "Longman\\LaravelLodash\\Composer\\ComposerScripts::createPackageHash",
        . . .
    ],
    . . .
```

And in the `AppServiceProvider::boot` add these lines:

```
    . . .
    if (config('app.debug')) {
        $checker = new ComposerChecker(base_path());
        $checker->checkHash();
    }
    . . .
```

### Helper Functions

[](#helper-functions)

FunctionDescription`p(...$values): void`Add debug messages to the debugbar`get_db_query(): ?string`Get last executed database query`get_db_queries(): ?array`Get all executed database queries### Extended Classes

[](#extended-classes)

For this fuctional you should add `Longman\LaravelLodash\LodashServiceProvider::class` in the `config/app.php` file.

There is an extended classes via Laravel's builtin macros functionality

#### Request class

[](#request-class)

MethodDescription`getInt(string $name, int $default = 0): int`Return request field value as a integer`getBool(string $name, bool $default = false): bool`Return request field value as a boolean`getFloat(string $name, float $default = 0): float`Return request field value as a float`getString(string $name, string $default = ''): string`Return request field value as a string### Artisan Commands

[](#artisan-commands)

For this fuctional you should add `Longman\LaravelLodash\LodashServiceProvider::class` in the `config/app.php` file.

CommandDescription`php artisan clear-all`Clear entire cache and all cached routes, views, etc.`php artisan db:clear`Drop all tables from database. Options:
--database= : The database connection to use.
--force : Force the operation to run when in production.
--pretend : Dump the SQL queries that would be run.`php artisan db:dump`Dump database to sql file using mysqldump CLI utility. Options:
--database= : The database connection to use.
--path= : Folder path for store database dump files.`php artisan db:restore {file}`Restore database from sql file using mysqldump CLI utility. Options:
--database= : The database connection to use.
--force : Force the operation to run when in production`php artisan log:clear`Clear log files from `storage/logs` recursively. Options:
--force : Force the operation to run when in production.`php artisan user:add {email} {password?}`Create a new user. Options:
--guard= : The guard to use.`php artisan user:password {email} {password?}`Update/reset user password. Options:
--guard= : The guard to use.### Middleware List

[](#middleware-list)

#### XssSecurity

[](#xsssecurity)

Sets XSS Security headers. Can be configured excluded URI-s, etc in the `config/lodash.php` .

#### SimpleBasicAuth

[](#simplebasicauth)

Add simple basic auth to a route.

In the `config/auth.php` you have to add:

```
    . . .
    'simple' => [
        'enabled'  => env('SIMPLE_AUTH_ENABLED', true),
        'user'     => env('SIMPLE_AUTH_USER', 'user'),
        'password' => env('SIMPLE_AUTH_PASS', 'secret'),
    ],
    . . .
```

### Blade Directives

[](#blade-directives)

For this functional you should add `Longman\LaravelLodash\LodashServiceProvider::class` in the `config/app.php` file.

DirectiveDescription`@datetime($date);`Display relative time. Example:
`$date = Carbon\Carbon::now();`
`@datetime($date);``@plural($count, $word)`Pluralization helper. Example:
`@plural(count($posts), 'post')`
Produces '1 post' or '2 posts', depending on how many items in $posts there are### Misc

[](#misc)

#### SelfDiagnosis Checks

[](#selfdiagnosis-checks)

For using this checks, you have to install the package: [laravel-self-diagnosis](https://github.com/beyondcode/laravel-self-diagnosis)

#### Available Disk Space Check

[](#available-disk-space-check)

```
...
\Longman\LaravelLodash\SelfDiagnosis\Checks\AvailableDiskSpace::class => [
    'paths' => [
        '/' => '100G', // At least 100G should be available for the path "/"
        '/var/www' => '5G',
    ],
],
...
```

#### Filesystem Disks Are Available

[](#filesystem-disks-are-available)

```
...
\Longman\LaravelLodash\SelfDiagnosis\Checks\FilesystemsAreAvailable::class => [
    'disks' => [
        'local',
        's3',
    ],
],
...
```

#### Elasticsearch Health Check

[](#elasticsearch-health-check)

```
...
\Longman\LaravelLodash\SelfDiagnosis\Checks\ElasticsearchCanBeAccessed::class => [
    'client' => ElasticSearchClient::class,
],
...
```

#### Php Ini Options Check

[](#php-ini-options-check)

```
...
\Longman\LaravelLodash\SelfDiagnosis\Checks\PhpIniOptions::class => [
    'options' => [
        'upload_max_filesize' => '>=128M',
        'post_max_size'       => '>=128M',
        'memory_limit'        => '>=128M',
        'max_input_vars'      => '>=10000',
        'file_uploads'        => '1',
        'disable_functions'   => '',
    ],
],
...
```

#### Php Ini Options Check

[](#php-ini-options-check-1)

```
...
\Longman\LaravelLodash\SelfDiagnosis\Checks\RedisCanBeAccessed::class => [
    'default_connection' => true,
    'connections'        => ['sessions'],
],
...
```

#### Servers Are Pingable Check

[](#servers-are-pingable-check)

```
...
\Longman\LaravelLodash\SelfDiagnosis\Checks\ServersArePingable::class => [
    'servers' => [
        [
            'host'    => config('app.url'),
            'port'    => 80,
            'timeout' => 1,
        ],
        [
            'host'    => 'sqs.eu-west-1.amazonaws.com',
            'port'    => 443,
            'timeout' => 3,
        ],
        [
            'host'    => 'www.googleapis.com',
            'port'    => 443,
            'timeout' => 3,
        ],
    ],
],
...
```

#### Horizon is running

[](#horizon-is-running)

```
...
\Longman\LaravelLodash\SelfDiagnosis\Checks\HorizonIsRunning::class,
...
```

TODO
----

[](#todo)

write more tests and add more features

Troubleshooting
---------------

[](#troubleshooting)

If you like living on the edge, please report any bugs you find on the [laravel-lodash issues](https://github.com/akalongman/laravel-lodash/issues) page.

Contributing
------------

[](#contributing)

Pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md) for information.

License
-------

[](#license)

Please see the [LICENSE](LICENSE.md) included in this repository for a full copy of the MIT license, which this project is licensed under.

Credits
-------

[](#credits)

- [Avtandil Kikabidze aka LONGMAN](https://github.com/akalongman)

Full credit list in [Contributors](https://github.com/akalongman/laravel-lodash/graphs/contributors)

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance69

Regular maintenance activity

Popularity45

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity93

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 93% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~74 days

Total

114

Last Release

435d ago

Major Versions

7.1.3 → 8.0.02022-07-21

8.0.1 → 9.0.02023-03-22

9.0.4 → 10.0.02024-01-31

10.3.0 → 11.0.02024-05-14

11.0.2 → 12.0.02024-09-06

PHP version history (11 changes)0.0.1PHP &gt;=7.0

1.0.0PHP &gt;=7.1.3

1.0.4PHP ^7.2

2.0.2PHP ^7.3

4.0.0PHP ^7.4

4.0.12PHP ^7.4|^8.0

5.0.0PHP ^8.0

6.0.0PHP ^8.0.2

7.0.0PHP ^8.1.0

9.0.0PHP ^8.1|^8.2

10.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ce7f33760f36c96e98898e3c61da6d9be21cbccc37cf628005d6076d09a7720d?d=identicon)[LONGMAN](/maintainers/LONGMAN)

---

Top Contributors

[![akalongman](https://avatars.githubusercontent.com/u/423050?v=4)](https://github.com/akalongman "akalongman (265 commits)")[![dealense7](https://avatars.githubusercontent.com/u/60123889?v=4)](https://github.com/dealense7 "dealense7 (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![ankaraWyaro](https://avatars.githubusercontent.com/u/157008301?v=4)](https://github.com/ankaraWyaro "ankaraWyaro (4 commits)")[![beso94](https://avatars.githubusercontent.com/u/17880281?v=4)](https://github.com/beso94 "beso94 (2 commits)")[![neoighodaro](https://avatars.githubusercontent.com/u/807318?v=4)](https://github.com/neoighodaro "neoighodaro (1 commits)")[![papavadze](https://avatars.githubusercontent.com/u/6769758?v=4)](https://github.com/papavadze "papavadze (1 commits)")

---

Tags

commandshacktoberfestlaravellaravel5lodashmiddlewarestoolsuseful-scriptsutilitieslaravelawsredissqstoolsutilitiesphpredislodashigbinary

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/longman-laravel-lodash/health.svg)

```
[![Health](https://phpackages.com/badges/longman-laravel-lodash/health.svg)](https://phpackages.com/packages/longman-laravel-lodash)
```

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[vetruvet/laravel-phpredis

Use phpredis as the redis connection in Laravel

43123.7k](/packages/vetruvet-laravel-phpredis)[encore/redis-manager

Redis manager for laravel

25243.1k](/packages/encore-redis-manager)[byerikas/cache-tags

Allows for Redis/Valkey cache flushing multiple tagged items by a single tag.

1413.9k](/packages/byerikas-cache-tags)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
