Download the PHP package longman/laravel-lodash without Composer
On this page you can find all versions of the php package longman/laravel-lodash. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-lodash
Laravel Lodash
This package adds lot of useful functionality to the Laravel >=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
- Installation
- Usage
- General
- Enable Debug Mode depending on visitor's IP Address
- Add created_by, updated_by and deleted_by to the eloquent models
- Use UUID in the Eloquent Models
- Eager loading of limited many to many relations via subquery or union
- Redis using igbinary
- Redis client side sharding
- AWS SQS Fifo Queue
- Elasticsearch Integration
- Check if installed packages are in sync with composer.lock
- Helper Functions
- Extended Classes
- Request Class
- Artisan Commands
- Middleware List
- XssSecurity
- SimpleBasicAuth
- Blade Directives
- Misc
- SelfDiagnosis Checks
- General
- TODO
- Troubleshooting
- Contributing
- License
- Credits
Installation
Install this package through Composer.
Run a command in your command line:
composer require longman/laravel-lodash
Add LodashServiceProvider
to your service providers list in the app.php
Copy the package config and translations to your application with the publish command:
php artisan vendor:publish --provider="Longman\LaravelLodash\LodashServiceProvider"
Usage
General
Enable Debug Mode depending on visitor's 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:
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:
Use UUID in the Eloquent Models
For this just add Longman\LaravelLodash\Eloquent\UuidAsPrimary
trait to your model and also
update related migration file:
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 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.
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
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 https://laravel.com/docs/5.5/redis#phpredis
After that include Cache and Redis service providers in the app.php
before your App providers:
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 https://github.com/phpredis/phpredis#setoption
Redis client side sharding
PhpRedis extension along with native Redis Cluster, also supports client-side sharding. 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 :smile:
Config example:
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:
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:
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:
Now you can add the configuration in the services.php
under config
folder:
You can use Elasticsearch integration via
Also you can perform search via searchable query object. Just create class and
implement ElasticsearchQueryContract
and you can pass object to performSearch
method
Check if installed packages are in sync with composer.lock
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
:
And in the AppServiceProvider::boot
add these lines:
Helper Functions
Function | Description |
---|---|
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
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
Method | Description |
---|---|
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
For this fuctional you should add Longman\LaravelLodash\LodashServiceProvider::class
in the config/app.php
file.
Command | Description |
---|---|
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
XssSecurity
Sets XSS Security headers. Can be configured excluded URI-s, etc in the config/lodash.php
.
SimpleBasicAuth
Add simple basic auth to a route.
In the config/auth.php
you have to add:
Blade Directives
For this functional you should add Longman\LaravelLodash\LodashServiceProvider::class
in the config/app.php
file.
Directive | Description |
---|---|
@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
SelfDiagnosis Checks
For using this checks, you have to install the package: laravel-self-diagnosis
Available Disk Space Check
Filesystem Disks Are Available
Elasticsearch Health Check
Php Ini Options Check
Php Ini Options Check
Servers Are Pingable Check
Horizon is running
TODO
write more tests and add more features
Troubleshooting
If you like living on the edge, please report any bugs you find on the laravel-lodash issues page.
Contributing
Pull requests are welcome. See CONTRIBUTING.md for information.
License
Please see the LICENSE included in this repository for a full copy of the MIT license, which this project is licensed under.
Credits
Full credit list in Contributors