{"id":14974434,"url":"https://github.com/akalongman/laravel-lodash","last_synced_at":"2025-05-16T13:03:25.695Z","repository":{"id":37587474,"uuid":"106134312","full_name":"akalongman/laravel-lodash","owner":"akalongman","description":"Extra useful functional for Laravel","archived":false,"fork":false,"pushed_at":"2025-05-12T11:17:17.000Z","size":848,"stargazers_count":94,"open_issues_count":1,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-13T20:45:31.899Z","etag":null,"topics":["commands","hacktoberfest","laravel","laravel5","lodash","middlewares","tools","useful-scripts","utilities"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akalongman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-10-07T22:20:24.000Z","updated_at":"2025-05-12T11:17:20.000Z","dependencies_parsed_at":"2022-08-25T15:51:55.855Z","dependency_job_id":"e4d014f4-ea6a-49f7-9659-8b6cbf408a2f","html_url":"https://github.com/akalongman/laravel-lodash","commit_stats":{"total_commits":234,"total_committers":7,"mean_commits":33.42857142857143,"dds":0.0854700854700855,"last_synced_commit":"cf074f7b75b91e41cbe95e0eb4b8b5f44900af7a"},"previous_names":[],"tags_count":114,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akalongman%2Flaravel-lodash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akalongman%2Flaravel-lodash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akalongman%2Flaravel-lodash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akalongman%2Flaravel-lodash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akalongman","download_url":"https://codeload.github.com/akalongman/laravel-lodash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254032114,"owners_count":22002880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["commands","hacktoberfest","laravel","laravel5","lodash","middlewares","tools","useful-scripts","utilities"],"created_at":"2024-09-24T13:50:33.585Z","updated_at":"2025-05-16T13:03:25.656Z","avatar_url":"https://github.com/akalongman.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Lodash\n\n[![Build Status](https://img.shields.io/travis/akalongman/laravel-lodash/master.svg?style=flat-square)](https://travis-ci.org/akalongman/laravel-lodash)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/akalongman/laravel-lodash.svg?style=flat-square)](https://scrutinizer-ci.com/g/akalongman/laravel-lodash/?branch=master)\n[![Code Quality](https://img.shields.io/scrutinizer/g/akalongman/laravel-lodash.svg?style=flat-square)](https://scrutinizer-ci.com/g/akalongman/laravel-lodash/?branch=master)\n[![Latest Stable Version](https://img.shields.io/github/tag/akalongman/laravel-lodash.svg?style=flat-square)](https://github.com/akalongman/laravel-lodash/tags)\n[![Total Downloads](https://img.shields.io/packagist/dt/Longman/laravel-lodash.svg)](https://packagist.org/packages/longman/laravel-lodash)\n[![Downloads Month](https://img.shields.io/packagist/dm/Longman/laravel-lodash.svg)](https://packagist.org/packages/longman/laravel-lodash)\n[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n\nThis package adds lot of useful functionality to the Laravel \u003e=8.0 project\n\n__Note:__ For Laravel older than 5.8 use the package version 1.*, for older than 8.0 - version 4.*\n\n## Table of Contents\n- [Installation](#installation)\n- [Usage](#usage)\n    - [General](#general)\n        - [Enable Debug Mode depending on visitor's IP Address](#enable-debug-mode-depending-on-visitors-ip-address)\n        - [Add created_by, updated_by and deleted_by to the eloquent models](#add-created_by-updated_by-and-deleted_by-to-the-eloquent-models)\n        - [Use UUID in the Eloquent Models](#use-uuid-in-the-eloquent-models)\n        - [Eager loading of limited many to many relations via subquery or union](#eager-loading-of-limited-many-to-many-relations-via-subquery-or-union)\n        - [Redis using igbinary](#redis-using-igbinary)\n        - [Redis client side sharding](#redis-client-side-sharding)\n        - [AWS SQS Fifo Queue](#aws-sqs-fifo-queue)\n        - [Elasticsearch Integration](#elasticsearch-integration)\n        - [Check if installed packages are in sync with composer.lock](#check-if-installed-packages-are-in-sync-with-composer.lock)\n    - [Helper Functions](#helper-functions)\n    - [Extended Classes](#extended-classes)\n        - [Request Class](#request-class)\n    - [Artisan Commands](#artisan-commands)\n    - [Middleware List](#middleware-list)\n        - [XssSecurity](#xsssecurity)\n        - [SimpleBasicAuth](#simplebasicauth)\n    - [Blade Directives](#blade-directives)\n    - [Misc](#misc)\n        - [SelfDiagnosis Checks](#selfdiagnosis-checks)\n- [TODO](#todo)\n- [Troubleshooting](#troubleshooting)\n- [Contributing](#contributing)\n- [License](#license)\n- [Credits](#credits)\n\n## Installation\n\nInstall this package through [Composer](https://getcomposer.org/).\n\nRun a command in your command line:\n\n    composer require longman/laravel-lodash\n\nAdd `LodashServiceProvider` to your service providers list in the `app.php`\n\n```php\n'providers' =\u003e [\n    . . .\n    /*\n     * Package Service Providers...\n     */\n    Longman\\LaravelLodash\\ServiceProvider::class,\n    . . .\n],\n```\n\nCopy the package config and translations to your application with the publish command:\n\n    php artisan vendor:publish --provider=\"Longman\\LaravelLodash\\LodashServiceProvider\"\n\n\n## Usage\n\n### General\n\n#### Enable Debug Mode depending on visitor's IP Address \n\nAdd `Longman\\LaravelLodash\\Debug\\DebugServiceProvider::class` in to `config/app.php`\nand specify debug IP's in your `config/lodash.php` config file:\n```php\n    . . .\n    'debug' =\u003e [\n        'ips' =\u003e [ // IP list for enabling debug mode\n            //'127.0.0.1',\n        ],\n    ],\n    . . .\n```\n\n#### Add created_by, updated_by and deleted_by to the eloquent models \n\nSometimes we need to know who created, updated or deleted entry in the database.\n\nFor this just add `Longman\\LaravelLodash\\Eloquent\\UserIdentities` trait to your model and also\nupdate migration file adding necessary columns:\n\n```php\n    $table-\u003eunsignedInteger('created_by')-\u003enullable();\n    $table-\u003eunsignedInteger('updated_by')-\u003enullable();\n    $table-\u003eunsignedInteger('deleted_by')-\u003enullable();\n```\n\n#### Use UUID in the Eloquent Models\n\nFor this just add `Longman\\LaravelLodash\\Eloquent\\UuidAsPrimary` trait to your model and also\nupdate related migration file:\n\n```php\n    $table-\u003euuid('id')-\u003eprimary();\n```\n\nAlso there is possible to specify uuid version via defining `uuidVersion` property in the model class.\n\n#### Eager loading of limited many to many relations via subquery or union\n\nEager load many to many relations with limit via subquery or union. \nFor using this feature, add `Longman\\LaravelLodash\\Eloquent\\ManyToManyPreload` trait to the models.\nAfter that you can use methods `limitPerGroupViaUnion()` and `limitPerGroupViaSubQuery()`.\nFor example you want to select users and 3 related user photos per user. \n\n```php\n    $items = (new User)-\u003ewith([\n        'photos' =\u003e function (BelongsToMany $builder) {\n            // Select via union. There you should pass pivot table fields array\n            $builder-\u003elimitPerGroupViaUnion(3, ['user_id', 'photo_id']);\n            // or\n            // Select via subquery\n            $builder-\u003elimitPerGroupViaSubQuery(3);\n        }, 'other.relation1', 'other.relation2'\n    ]);\n    $items = $items-\u003eget();\n```\n\nNow each user model have 3 photos model selected via one query. \nYou can specify additional where clauses or order by fields before the group method call.\n\n#### Redis using igbinary\n\nIgbinary is a drop in replacement for the standard php serializer. \nIgbinary stores php data structures in compact binary form. \nSavings are significant when using Redis or similar memory based storages for serialized data.\nVia Igbinary repetitive strings are stored only once. Collections of Eloquent objects benefit significantly from this.\n\nBy default Laravel does not provide an option to enable igbinary serializer for PhpRedis connection \nand you have to use LaravelLodash implementation for this.\n\nFirst of all, make sure you enabled PhpRedis driver by this guide https://laravel.com/docs/5.5/redis#phpredis\n\nAfter that include Cache and Redis service providers in the `app.php` before your App providers:\n```php\n    . . .\n    Longman\\LaravelLodash\\Cache\\CacheServiceProvider::class,\n    Longman\\LaravelLodash\\Redis\\RedisServiceProvider::class,\n    . . .\n```\nYou can remove Laravel's Cache and Redis service providers from the config, \nbecause LaravelLodash providers are extended from them and therefore implements entire functional.\n\nNow you can specify the serializer in your `database.php` under `config` folder:\n\nAlso, you can specify other options like `scan` or etc. See https://github.com/phpredis/phpredis#setoption\n\n#### Redis client side sharding\n\nPhpRedis extension along with native Redis Cluster, also supports [client-side sharding](https://github.com/phpredis/phpredis/blob/develop/arrays.markdown#readme).\nThis feature is very useful, when you want distribute your data between multiple servers, but do not want use native Redis Cluster.\n\nIts not implemented in the Laravel by default. We tried to fix this :smile:\n\nConfig example:\n\n```php\n    . . .\n    'redis' =\u003e [\n        'client' =\u003e 'phpredis',\n        \n        'clusters' =\u003e [\n            'options' =\u003e [\n                'lazy_connect'      =\u003e true,\n                'connect_timeout'   =\u003e 1,\n                'read_timeout'      =\u003e 3,\n                'password'          =\u003e env('REDIS_PASSWORD', null),\n                'database'          =\u003e env('REDIS_DATABASE', 0),\n                'prefix'            =\u003e env('REDIS_PREFIX'),\n                'serializer'        =\u003e Redis::SERIALIZER_IGBINARY,\n                'compression'       =\u003e Redis::COMPRESSION_ZSTD,\n                'compression_level' =\u003e Redis::COMPRESSION_ZSTD_DEFAULT,\n            ],\n\n            'default' =\u003e [\n                [\n                    'host' =\u003e env('REDIS_SHARD1_HOST', '127.0.0.1'),\n                    'port' =\u003e env('REDIS_SHARD1_PORT', 6379),\n                ],\n                [\n                    'host' =\u003e env('REDIS_SHARD2_HOST', '127.0.0.2'),\n                    'port' =\u003e env('REDIS_SHARD2_PORT', 6379),\n                ],\n                . . .\n            ],\n        ],\n    ],\n    . . .\n```\n\n#### AWS SQS Fifo Queue\n\nLaravel by default does not supports AWS FIFO queues and this package fixes it.\n\nYou have to add `QueueServiceProvider` service provider in the `app.php` before your App providers:\n```php\n    . . .\n    Longman\\LaravelLodash\\Queue\\QueueServiceProvider::class,\n    . . .\n```\nYou can remove Laravel's Queue service provider from the config, \nbecause LaravelLodash provider are extended from that and therefore implements entire functional.\n\nNow you can add the new connection in the `queue.php` under `config` folder:\n\n```php\n    . . .\n    'sqs_fifo' =\u003e [\n        'driver'  =\u003e 'sqs.fifo',\n        'version' =\u003e 'latest',\n        'key'     =\u003e env('AWS_ACCESS_KEY_ID'),\n        'secret'  =\u003e env('AWS_SECRET_ACCESS_KEY'),\n        'prefix'  =\u003e env('AWS_SQS_URL'),\n        'queue'   =\u003e env('AWS_SQS_DEFAULT_QUEUE'),\n        'region'  =\u003e env('AWS_DEFAULT_REGION'),\n        'options' =\u003e [\n            'type'      =\u003e 'fifo', // fifo, normal\n            'polling'   =\u003e 'long', // long, short\n            'wait_time' =\u003e 20,\n        ],\n    ],\n    . . .\n```\n\n#### Elasticsearch Integration\n\nFirst of all you have to install official elasticsearch php sdk:\n\n    composer require elasticsearch/elasticsearch\n\nAfter add `ElasticsearchServiceProvider` service provider in the `app.php` before your App providers:\n```php\n    . . .\n    Longman\\LaravelLodash\\Elasticsearch\\ElasticsearchServiceProvider::class,\n    . . .\n```\nNow you can add the configuration in the `services.php` under `config` folder:\n\n```php\n    . . .\n    'elasticsearch' =\u003e [\n        'enabled'          =\u003e env('ELASTICSEARCH_ENABLED', false),\n        'log_channel'      =\u003e ['daily'],\n        'hosts'            =\u003e [\n            [\n                'host' =\u003e env('ELASTICSEARCH_HOST', 'localhost'),\n                'port' =\u003e env('ELASTICSEARCH_PORT', 9200),\n            ],\n        ],\n        'connectionParams' =\u003e [\n            'client' =\u003e [\n                'timeout'         =\u003e env('ELASTICSEARCH_TIMEOUT', 3),\n                'connect_timeout' =\u003e env('ELASTICSEARCH_TIMEOUT', 3),\n            ],\n        ],\n    ],\n    . . .\n```\n\nYou can use Elasticsearch integration via \n\n```php\n    $elasticsearch_manager = app(ElasticsearchManagerContract::class);\n    \n    // Call wrapped methods\n    $elasticsearch_manager-\u003ecreateIndex('some-index');\n    \n    // Or get native client and access their methods\n    $client = $elasticsearch_manager-\u003egetClient();\n    $client-\u003eindices()-\u003ecreate($params);\n\n```\n\nAlso you can perform search via searchable query object. Just create class and \nimplement `ElasticsearchQueryContract` and you can pass object to `performSearch` method\n\n```php\n\n    $elasticsearch_manager = app(ElasticsearchManagerContract::class);\n    $results = $elasticsearch_manager-\u003eperformSearch($query); \n\n```\n\n## Check if installed packages are in sync with composer.lock\n\nFor development purposes, it is recommended to check if vendor folder is in sync with composer.lock file.\n\nFor this, in composer.json you have to add script `ComposerScripts::createPackageHash`:\n```json\n    . . .\n    \"post-autoload-dump\": [\n        \"Longman\\\\LaravelLodash\\\\Composer\\\\ComposerScripts::createPackageHash\",\n        . . .\n    ],\n    . . .\n```\n\nAnd in the `AppServiceProvider::boot` add these lines:\n\n```php\n    . . .\n    if (config('app.debug')) {\n        $checker = new ComposerChecker(base_path());\n        $checker-\u003echeckHash();\n    }\n    . . .\n```\n\n\n### Helper Functions\n\nFunction  | Description\n------------- | -------------\n`p(...$values): void`  |  Add debug messages to the debugbar\n`get_db_query(): ?string`  |  Get last executed database query\n`get_db_queries(): ?array`  |  Get all executed database queries\n\n### Extended Classes\n\nFor this fuctional you should add `Longman\\LaravelLodash\\LodashServiceProvider::class` in the `config/app.php` file.\n\nThere is an extended classes via Laravel's builtin macros functionality\n\n#### Request class\n\nMethod  | Description\n------------- | -------------\n`getInt(string $name, int $default = 0): int`  |  Return request field value as a integer\n`getBool(string $name, bool $default = false): bool`  |  Return request field value as a boolean\n`getFloat(string $name, float $default = 0): float`  |  Return request field value as a float\n`getString(string $name, string $default = ''): string`  |  Return request field value as a string\n\n### Artisan Commands\n\nFor this fuctional you should add `Longman\\LaravelLodash\\LodashServiceProvider::class` in the `config/app.php` file.\n\nCommand  | Description\n------------- | -------------\n`php artisan clear-all`  |  Clear entire cache and all cached routes, views, etc.\n`php artisan db:clear`  |  Drop all tables from database. Options:\u003cbr/\u003e--database= : The database connection to use.\u003cbr/\u003e--force : Force the operation to run when in production.\u003cbr/\u003e--pretend : Dump the SQL queries that would be run.\n`php artisan db:dump`  |  Dump database to sql file using mysqldump CLI utility. Options:\u003cbr/\u003e--database= : The database connection to use.\u003cbr/\u003e--path= : Folder path for store database dump files.\n`php artisan db:restore {file}`  |  Restore database from sql file using mysqldump CLI utility. Options:\u003cbr/\u003e--database= : The database connection to use.\u003cbr/\u003e--force : Force the operation to run when in production\n`php artisan log:clear`  |  Clear log files from `storage/logs` recursively. Options:\u003cbr/\u003e--force : Force the operation to run when in production.\n`php artisan user:add {email} {password?}`  |  Create a new user. Options:\u003cbr/\u003e--guard= : The guard to use.\n`php artisan user:password {email} {password?}`  |  Update/reset user password. Options:\u003cbr/\u003e--guard= : The guard to use.\n\n\n### Middleware List\n\n#### XssSecurity\n\nSets XSS Security headers. Can be configured excluded URI-s, etc in the `config/lodash.php` .\n\n#### SimpleBasicAuth\n\nAdd simple basic auth to a route.\n\nIn the `config/auth.php` you have to add:\n\n```php\n    . . .\n    'simple' =\u003e [\n        'enabled'  =\u003e env('SIMPLE_AUTH_ENABLED', true),\n        'user'     =\u003e env('SIMPLE_AUTH_USER', 'user'),\n        'password' =\u003e env('SIMPLE_AUTH_PASS', 'secret'),\n    ],\n    . . .\n```\n\n\n### Blade Directives\n\nFor this functional you should add `Longman\\LaravelLodash\\LodashServiceProvider::class` in the `config/app.php` file.\n\nDirective  | Description\n------------- | -------------\n`@datetime($date);`  |  Display relative time. Example:\u003cbr/\u003e`$date = Carbon\\Carbon::now();`\u003cbr /\u003e`@datetime($date);`\n`@plural($count, $word)`  |  Pluralization helper. Example:\u003cbr/\u003e`@plural(count($posts), 'post')`\u003cbr /\u003eProduces '1 post' or '2 posts', depending on how many items in $posts there are\n\n\n### Misc\n\n#### SelfDiagnosis Checks\n\nFor using this checks, you have to install the package: [laravel-self-diagnosis](https://github.com/beyondcode/laravel-self-diagnosis)\n\n#### Available Disk Space Check\n\n```php\n...\n\\Longman\\LaravelLodash\\SelfDiagnosis\\Checks\\AvailableDiskSpace::class =\u003e [\n    'paths' =\u003e [\n        '/' =\u003e '100G', // At least 100G should be available for the path \"/\"\n        '/var/www' =\u003e '5G',\n    ],\n],\n...\n```\n\n#### Filesystem Disks Are Available\n\n```php\n...\n\\Longman\\LaravelLodash\\SelfDiagnosis\\Checks\\FilesystemsAreAvailable::class =\u003e [\n    'disks' =\u003e [\n        'local',\n        's3',\n    ],\n],\n...\n```\n\n#### Elasticsearch Health Check\n\n```php\n...\n\\Longman\\LaravelLodash\\SelfDiagnosis\\Checks\\ElasticsearchCanBeAccessed::class =\u003e [\n    'client' =\u003e ElasticSearchClient::class,\n],\n...\n```\n\n#### Php Ini Options Check\n\n```php\n...\n\\Longman\\LaravelLodash\\SelfDiagnosis\\Checks\\PhpIniOptions::class =\u003e [\n    'options' =\u003e [\n        'upload_max_filesize' =\u003e '\u003e=128M',\n        'post_max_size'       =\u003e '\u003e=128M',\n        'memory_limit'        =\u003e '\u003e=128M',\n        'max_input_vars'      =\u003e '\u003e=10000',\n        'file_uploads'        =\u003e '1',\n        'disable_functions'   =\u003e '',\n    ],\n],\n...\n```\n\n#### Php Ini Options Check\n\n```php\n...\n\\Longman\\LaravelLodash\\SelfDiagnosis\\Checks\\RedisCanBeAccessed::class =\u003e [\n    'default_connection' =\u003e true,\n    'connections'        =\u003e ['sessions'],\n],\n...\n```\n\n#### Servers Are Pingable Check\n\n```php\n...\n\\Longman\\LaravelLodash\\SelfDiagnosis\\Checks\\ServersArePingable::class =\u003e [\n    'servers' =\u003e [\n        [\n            'host'    =\u003e config('app.url'),\n            'port'    =\u003e 80,\n            'timeout' =\u003e 1,\n        ],\n        [\n            'host'    =\u003e 'sqs.eu-west-1.amazonaws.com',\n            'port'    =\u003e 443,\n            'timeout' =\u003e 3,\n        ],\n        [\n            'host'    =\u003e 'www.googleapis.com',\n            'port'    =\u003e 443,\n            'timeout' =\u003e 3,\n        ],\n    ],\n],\n...\n```\n\n#### Horizon is running\n\n```php\n...\n\\Longman\\LaravelLodash\\SelfDiagnosis\\Checks\\HorizonIsRunning::class,\n...\n```\n\n## TODO\n\nwrite more tests and add more features\n\n## Troubleshooting\n\nIf you like living on the edge, please report any bugs you find on the\n[laravel-lodash issues](https://github.com/akalongman/laravel-lodash/issues) page.\n\n## Contributing\n\nPull requests are welcome.\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for information.\n\n## License\n\nPlease see the [LICENSE](LICENSE.md) included in this repository for a full copy of the MIT license,\nwhich this project is licensed under.\n\n## Credits\n\n- [Avtandil Kikabidze aka LONGMAN](https://github.com/akalongman)\n\nFull credit list in [Contributors](https://github.com/akalongman/laravel-lodash/graphs/contributors)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakalongman%2Flaravel-lodash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakalongman%2Flaravel-lodash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakalongman%2Flaravel-lodash/lists"}