Download the PHP package zlt/lara-calls without Composer
On this page you can find all versions of the php package zlt/lara-calls. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zlt/lara-calls
More information about zlt/lara-calls
Files in zlt/lara-calls
Informations about the package lara-calls
A bunch of useful methods for Laravel
Table Of Contents
- Installation
- Available Methods
- Collection Macros
- onlyValues
- pluckMultiple
- sortInValue
- sortInValueDesc
- groupAndSortBy
- groupAndSortByDesc
- validation
- Builder Macros
- updateOrCreateWhen
- Global Helpers
- Calculate Execution Time
- Collection Macros
Installation
Requirements
- php : ^7.3 or ^8.0
- laravel : ^8.0
Install via composer
Publish config file.
Config file will contain
Note: If you've already published config, update your 'macros' in 'laravel-macros' config to use the latest methods.
Available Methods
Collection Macros
-
OnlyValues
This method can be used on
Collection
instance. This will return only values and will discard first level array keys. -
PluckMultiple
This method can be used on
Collection
instance. This method is similar toget()
on Eloquent Builder. You can pluck columns and their values that you only want. You can also pluck nested attributes if exists. -
SortInValue
This method will sort values of certain attribute in ascending order. You can also specify key to sort values of that attribute. To sort in descending order, use
sortInValueDesc
-
SortInValueDesc
This method is similar to
sortInValue
but will sort in descending order. -
GroupAndSortBy
This method is similar to
groupBy
but you can sort the returned collection. You can also provide a callback to modify the returned collection as you like. In order to sort the returned collection in descending order, you may usegroupAndSortByDesc
method. -
GroupAndSortByDesc
The
groupAndSortByDesc
method is similar togroupAndSortBy
but the returned collection is sorted in descending order. -
Validation
Validate the collection and perform subsequent
onSuccess
oronError
processes. In order to validate, you may provide array of validation rules or closure. If you provide validation rules, you can provide a parameter inside closure inonError
and that parameter would be an instance of\Illuminate\Support\MessageBag
.
Builder Macros
-
updateOrCreateWhen
This method is like Laravel's
updateOrCreate
method, but it accepts closure whether it should update or not if value is already existed. You can use this method with Eloquent.
Global Helpers
-
Calculate Execution Time
Calculate your function execution time in seconds.