mortenscheel/laravel-macros

v1.3.1 2022-09-01 08:08 UTC

This package is auto-updated.

Last update: 2024-03-29 03:52:09 UTC


README

Latest Version on Packagist Total Downloads

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.