Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Repository files navigation

Elevate

This package provides a library of macro functions for various Laravel components. Use them to augment the existing functionality offered by the likes of Blade, Collections, Stringable, and so on.

Initially, only a handful of macros are available. That said, the library has been designed so that it can handle dozens or even hundreds of macros being added over time. Each individual macro may also be disabled, thus ensuring that Laravel isn't spending precious time registering macros you are not using.

Installation

Pull in the package using composer

composer require caneara/elevate

Configuration

If you wish to make all of the macros available to your application, then you can skip this section. Otherwise, you should publish the configuration file using Artisan:

php artisan vendor:publish --provider="Elevate\ServiceProvider"

You may wish to disable a particular macro for one of the following reasons:

  1. Performance - if you aren't using the macro, or even the class itself, then disabling it will net a tiny performance boost.
  2. Conflicts - if you already have a macro for a class, or wish to create one with the same name, you should disable the Elevate macro to prevent conflicts.

To prevent a macro being registered, simply set its value to false:

'Blade' => [
'Blank' => true,
'Filled' => false,
];

Available macros

The following macros are currently available:

MacroClassDescription
filledBladeEnables the use of @filled() and @endfilled. Uses the filled() global helper under the hood. You may also use @else e.g. @filled() @else @endfilled
blankBladeEnables the use of @blank() and @endblank. Uses the blank() global helper under the hood. You may also use @else e.g. @blank() @else @endblank
appendIfStringableAppends the given string to the string if it doesn't already finish with it
collapseStringableTrims the string and replaces multiple whitespace characters with a single space
countStringableDetermine the total number of times the given string appears within the string
getStringableAdds a more friendly helper to access a fluent string's content e.g. Str::of('test')->get()
insertStringableInjects the given string at the given index
padLeftStringablePad the string to the given length from the left side
padRightStringablePad the string to the given length from the right side
possessiveStringableConverts the string to a possessive version e.g. Bob -> Bob's
prependIfStringablePrepends the given string to the string if it doesn't already start with it
segmentStringableSplits the string using the given delimiter, then retrieves the item at the given array index
toArrayStringableConverts the string into an array of characters
toggleStringableToggles the string between two states. Contains a $loose flag to allow the switching of a string that matches neither states
afterCollectionGet the next item from the collection
atCollectionRetrieve an item at an index
secondCollectionRetrieve item at the second index
thirdCollectionRetrieve item at the third index
fourthCollectionRetrieve item at the fourth index
fifthCollectionRetrieve item at the fifth index
sixthCollectionRetrieve item at the sixth index
seventhCollectionRetrieve item at the seventh index
eighthCollectionRetrieve item at the eighth index
ninthCollectionRetrieve item at the ninth index
tenthCollectionRetrieve item at the tenth index
beforeCollectionGet the previous item from the collection
carbonizeCollectionConvert all collection items into instances of CarbonImmutable
chunkByCollectionChunks the values from a collection into groups as long the given callback is true
collectByCollectionGet an item at a given key, and collect it
eachConsCollectionGet the following consecutive neighbours in a collection from a given chunk size
extractCollectionExtract keys from a collection
filterMapCollectionMap a collection and remove falsy values in one go
firstOrFailCollectionGet the first item or throw an exception
fromPairsCollectionTransform a collection into an associative array form collection item
globCollectionReturns a collection of a glob() result
groupByModelCollectionSimilar to groupBy, but groups the collection by an Eloquent model
headCollectionRetrieves first item from the collection
ifAnyCollectionExecutes the passed callable if the collection isn't empty
ifEmptyCollectionExecutes the passed callable if the collection is empty
noneCollectionChecks whether a collection doesn't contain any occurrences of a given item, key-value pair, or passing truth test
paginateCollectionCreate a LengthAwarePaginator instance for the items in the collection
parallelMapCollectionIdentical to map but each item in the collection will be processed in parallel
pluckToArrayCollectionReturns array of values of a given key
prioritizeCollectionMove elements to the start of the collection
rotateCollectionRotate the items in the collection with given offset
sectionByCollectionSplits a collection into sections grouped by a given key
simplePaginateCollectionCreate a Paginator instance for the items in the collection
sliceBeforeCollectionSlice the values out from a collection before the given callback is true
tailCollectionExtract the tail from a collection (everything except the first element)
toPairsCollectionTransform a collection into an array with pairs
transformKeysCollectionPerforms a transform operation, but on the collection's keys instead of its values
transposeCollectionRotate a multidimensional array, turning the rows into columns and the columns into rows
trimCollectionMaps over each item in the collection and calls PHP's trim() method on it
validateCollectionReturns true if the given callback returns true for every item
withSizeCollectionCreate a new collection with the specified amount of items

Contributing

Thank you for considering a contribution to Elevate. You are welcome to submit a PR containing a new macro or improvements to existing ones, however please also be sure to include a test or tests where appropriate.

Credits

The library includes macros and / or code obtained from the following open-source packages:

License

The MIT License (MIT). Please see License File for more information.

About

A package that provides a library of macro functions for various Laravel components.

Resources

Stars

30 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages