Download the PHP package sirmathays/convenient-laravel-macros without Composer
On this page you can find all versions of the php package sirmathays/convenient-laravel-macros. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sirmathays/convenient-laravel-macros
More information about sirmathays/convenient-laravel-macros
Files in sirmathays/convenient-laravel-macros
Package convenient-laravel-macros
Short Description Helpful macros for your Laravel project.
License MIT
Homepage https://matti.suoraniemi.com/creations/packages/convenient-laravel-macros
Informations about the package convenient-laravel-macros
This package provides some additional, convenient macros for you to use with your Laravel project.
Installation
Install the package with Composer:
composer require sirmathays/convenient-laravel-macros
The package registers itself automatically.
Macros
Here's a brief documentation on the macros the package provides.
Illuminate\Database\Eloquent\Builder
selectKey
whereLike
&orWhereLike
Illuminate\Database\Query\Builder
selectRawArr
Illuminate\Support\Collection
mergeMany
pluckMany
whereExtends
whereImplements
whereUses
Illuminate\Support\Arr
combine
fillKeys
join
zip
unzip
Illuminate\Support\Str
wrap
Illuminate\Support\Stringable
wrap
Carbon\CarbonPeriod
collect
Illuminate\Database\Eloquent\Builder::selectKey
Select the key of the model in the query (uses Model's getKey
method).
Illuminate\Database\Eloquent\Builder::whereLike
& orWhereLike
Illuminate\Database\Query\Builder::selectRawArr
Add raw select statements as an array, instead of as a one ugly string (selectRaw
).
Illuminate\Support\Collection::mergeMany
Merge multiple arrays/collections to the collection in one go.
Illuminate\Support\Collection::pluckMany
Pluck several keys from the collection items.
Illuminate\Support\Collection::whereExtends
Filter classes and/or objects that extend the given class.
Illuminate\Support\Collection::whereImplements
Filter classes and/or objects that implement the given interface.
Illuminate\Support\Collection::whereUses
Filter classes and/or objects that use the given trait.
Illuminate\Support\Arr::associate
Converts an array into a fully associative array by converting any values with an integer key to the value being the key filled with the given fill value. Values that have a string key already won't be touched.
Illuminate\Support\Arr::combine
Similar to array_combine
, but allows to have more keys than values. Keys without value will be set
as null.
Illuminate\Support\Arr::fillKeys
Fills given keys with given value. You can also set that only keys that already exist in the array
can become filled. In other words, if the key foo
is to be filled with value bar
, but the key
foo
doesn't already exist in the array, the array will remain unchanged.
Illuminate\Support\Arr::join
Collection's nice join method brought to Arr.
Illuminate\Support\Arr::zip
Zips the key and value together with the given zipper.
Illuminate\Support\Arr::unzip
Unzips keys to key and value with the given zipper.
Illuminate\Support\Str::wrap
Wraps the string with given character(s).
Illuminate\Support\Stringable::wrap
Wraps the string with given character(s).
Carbon\CarbonPeriod::collect
Extending the MacroServiceProvider
You can make your own pretty MacroServiceProviders by extending the MacroServiceProvider class provided by this package!
Here's an example:
The macro class referenced in the example above would look something like:
Commands
You can use make:macro <name>
to generate a macro file to help you with the structure. The command
supports --mixin
option (example: --mixin=/Illuminate/Support/Collection
). This will add a PHP
docblock above the macro class declaration with @mixin
tag.
The package also comes with macro:generate
command. If you have a provider class setup that extends
SirMathays\Convenience\Foundation\MacroServiceProvider
class, the command will go through the macros
defined in the provider and generate the ones that are missing. This way you can define multiple macros
you know you will have and then generate them in bulk. It is very similar to Laravel's event:generate
in its behavior.
For example:
Assuming ExampleMacro
doesn't exist yet, the command would then generate the macro class, automatically
also filling in the @mixin
tag.
License
Convenient Laravel Commands is open-sourced software licensed under the MIT license.
All versions of convenient-laravel-macros with dependencies
illuminate/support Version ^8.0
illuminate/console Version ^8.0
sirmathays/convenient-laravel-helpers Version ^2.0