mortenscheel / laravel-macros
Useful Laravel macros
Requires
- illuminate/support: ~5|^6.0|^7|^8|^9
Requires (Dev)
- mockery/mockery: ^1.1
- orchestra/testbench: ~5.0
- phpunit/phpunit: ~8.0
- sempro/phpunit-pretty-print: ^1.0
Suggests
- tutorigo/laravel-ide-macros: Get IDE auto-completion for macros
This package is auto-updated.
Last update: 2024-11-06 11:19:28 UTC
README
A collection of useful macros for Laravel. See details below.
Installation
Via Composer
$ composer require mortenscheel/laravel-macros
Macros
Carbon
Carbon::upToNearest(int $minutes): Carbon
Rounds up to the nearest minute divisible by $minutes
Carbon::downToNearest(int $minutes): Carbon
Rounds down to the nearest minute divisible by $minutes
Note
If the original time is already divisible by $minutes
and the seconds are exactly zero, no rounding will occur.
Filesystem
File::modify(string $path, \Closure $callback)
The $callback
will receive the current content of the file, and the return value will be stored back to the same $path
Collection
Collection::sortKeysRecursively(bool $descending = false): Collection
Sorts the Collection by keys, recursively.
Useful for comparing nested associative arrays where the contents may be sorted differently.
Response
Response::plain($body): Response
Convenient macro for returning a plain text response. Simply adds aContent-Type: text/plain;charset=UTF-8
header
Builder
Builder::inlineQuery(): string
Returns the Query SQL with bindings inserted. Useful for debugging queries, but should never be used in production.
Change log
Please see the changelog for more information on what has changed recently.
Testing
$ ./vendor/bin/phpunit
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email author email instead of using the issue tracker.
Credits
License
MIT license. Please see the license file for more information.