nham24 / macroable
A set of useful Laravel macros
0.1.1
2023-07-14 07:50 UTC
Requires
- php: >=7.2
- illuminate/support: >=5.8
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.21
- mockery/mockery: ^1.6.2
- orchestra/testbench: ^8.5.9
- pestphp/pest: ^2.0
- phpunit/phpunit: 10.2.2
README
This repository contains some useful macros and extensible Macroable trait.
Installation
You can pull in the package via composer:
composer require nham24/macroable
The package will automatically register itself.
Collections
paginate
Create a LengthAwarePaginator
instance for the items in the collection.
collect($posts)->paginate(5);
This paginates the contents of $posts
with 5 items per page. paginate
accepts quite some options, head over to the Laravel docs for an in-depth guide.
paginate(int $perPage = 15, string $pageName = 'page', int $page = null, int $total = null, array $options = [])
Request
isApi
Check if the request is an API request.
$request = request()->isApi();