Download the PHP package imliam/laravel-macros without Composer
On this page you can find all versions of the php package imliam/laravel-macros. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download imliam/laravel-macros
More information about imliam/laravel-macros
Files in imliam/laravel-macros
Package laravel-macros
Short Description A collection of miscellaneous methods to extend some of Laravel's core classes through the use of macros and mixins
License MIT
Homepage https://github.com/imliam/laravel-macros
Informations about the package laravel-macros
Laravel Macros
A collection of miscellaneous methods to extend some of Laravel's core classes through the use of macros and mixins.
- Laravel Macros
- Installation
- Usage
- Illuminate\Support\Collection
Collection@sortByDate($key = null)
Collection@sortByDateDesc($key = null)
Collection@keysToValues()
Collection@valuesToKeys()
- Illuminate\Database\Query\Builder
Builder@if($condition, $column, $operator, $value)
- Illuminate\Http\Request
Request@replace($key, $value)
- Illuminate\Support\Facades\Route
- Illuminate\Support\Collection
- Testing
- Changelog
- Contributing
- Security
- Credits
- License
Installation
You can install the package with Composer using the following command:
Usage
Once installed, all macros will automatically be registered and methods will immediately be available for use.
Illuminate\Support\Collection
Collection@sortByDate($key = null)
Sort the values in a collection by a datetime value.
To sort a simple list of dates, call the method without passing any arguments to it.
To sort a collection where the date is in a specific key, pass the key name when calling the method.
Additionally, you can pass a callback to the method to choose more precisely what is sorted.
Collection@sortByDateDesc($key = null)
This method has the same signature as the sortByDate
method, but will sort the collection in the opposite order.
Collection@keysToValues()
Change the collection so that all values are equal to the corresponding key.
Collection@valuesToKeys()
Change the collection so that all keys are equal to their corresponding value.
Illuminate\Database\Query\Builder
Builder@if($condition, $column, $operator, $value)
Conditionally add where clause to the query builder. See Mohamed Said's blog post for more information.
Keep chaining methods onto a query being built without having to break it up. Take code like this:
And clean it up into this:
Illuminate\Http\Request
Request@replace($key, $value)
Manipulate the request object by replacing a value, or even adding a new one.
Illuminate\Support\Facades\Route
Route@viewDir($path, $viewDirectory = '', $data = [])
Mimics the functionality offered by Route::view() method but extends it by rerouting requested the URI at any number of sub-levels to match a view directory in the code base.
This makes it possible to create views with static content and not need to worry about updating routes to match them or using a CMS-style solution to manage them.
For an example, to see how it works, imagine the following route definition:
And the following directory structure for the views:
The following routes will be generated to match each of the views in the given directory:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Liam Hammett
- All Contributors
License
The MIT License (MIT). Please see License File for more information.