nham24 /
一组有用的 Laravel 宏
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
此存储库包含一些有用的宏和可扩展的 Macroable 特性。
安装
您可以通过 composer 拉取此包。
composer require nham24/macroable
包将自动注册自身。
集合
paginate
为集合中的项目创建一个 LengthAwarePaginator
实例。
collect($posts)->paginate(5);
此将 $posts
的内容分页显示,每页 5 项。paginate
接受许多选项,请参阅 Laravel 文档 以获取详细指南。
paginate(int $perPage = 15, string $pageName = 'page', int $page = null, int $total = null, array $options = [])
请求
isApi
检查请求是否为 API 请求。
$request = request()->isApi();