curtissaunders/laravel-helpers
Composer 安装命令:
composer require curtissaunders/laravel-helpers
包简介
A series of helper functions for Laravel 5
README 文档
README
Installation
This package requires PHP 5.6+, and includes a Laravel 5 Service Provider.
To install through composer include the package in your composer.json.
"curtissaunders/laravel-helpers": "^1.0"
Run composer install or composer update to download the dependencies or you can run composer require curtissaunders/laravel-helpers.
Laravel 5 Integration
To use the package with Laravel 5, add the Helper Service Provider to the list of service providers
in app/config/app.php.
'providers' => [
CurtisSaunders\LaravelHelpers\HelpersServiceProvider::class
];
Available helpers
- versioned_asset will apply a cache busting query string to your assets.
- concat will concatenate strings together
- concat_ws will concatenate strings together with the separator being defined as the first argument
- generate_uuid will generate a valid RFC 4122 UUID
- route_is/routeIs will check if the current route matches the route passed
- query_log_to_sql will allow you to log a database query to a variable and dump it out for easy debugging
- combine_query will combine a query with its bindings
Example of versioned_asset:
{{ versioned_asset('images/photo.png') }}
outputs:
http://mysite.com/images/photo.png?v=392104829
Example of concat:
{{ concat('John', 'Terry', 'Dave') }}
outputs:
John Terry Dave
Example of concat_ws:
{{ concat_ws(' - ', 'John', 'Terry', 'Dave') }}
outputs:
John - Terry - Dave
Example of generate_uuid:
{{ generate_uuid() }}
outputs:
e4eaaaf2-d142-11e1-b3e4-080027620cdd
When using the generate_uuid function, you are able to generate valid RFC 1, 3, 4 and 5 versions. In order to change
the version, simply pass the version number you require as the first argument (defaults to 1). For example, to generate
a version 4 Uuid, you can do the following:
{{ generate_uuid(4) }}
outputs:
25769c6c-d34d-4bfe-ba98-e0ee856f3e7a
For versions 3 and 5, you are also required to pass in a string as the second argument. This is hashed and used when generating the Uuid. For example:
{{ generate_uuid(3, 'php.net') }}
outputs:
11a38b9a-b3da-360f-9353-a5a725514269
Example of route_is() or routeIs():
Examples shown in Laravel Blade
@if(route_is('about.index'))
// Do something
@else
// Do something else
@endif
Alternatively
@if(routeIs('about.index'))
// Do something
@else
// Do something else
@endif
You can also check for specific parameters by passing them in an array as the second argument. For example, you may want to check that you're on a specific product category to apply an "active" class to a link. Consider the below when looping through category links:
@foreach($categories as $category)
<a href="{{ route('product.category', [$category->slug]) }}" class="{{ route_is('product.category', ['categorySlug' => $category->slug]) ? 'active' : '' }}">
{{ $category->name }}
</a>
@endforeach
The above would apply a class of "active" when you're on the corresponding page to that link.
Example of query_log_to_sql:
// Enable laravel's query log
DB::connection()->enableQueryLog();
... // Do database transactions ...
// Get all the queries ran since the query log was enabled
$queryLog = DB::getQueryLog();
// Combine the query logs ran with their bindings into the sql that was ran
$sqlQueries = query_log_to_sql($queryLog);
// Returns an array of all the sql queries ran with their bindings in place, useful for quick debugging
dd($sqlQueries);
Example of combine_query:
// Create a query using Eloquent
$eloquentQuery = UserModel::where('email', '=', 'user.name@example.com');
// Combine the Eloquent query sql and bindings into a query you can run in mysql
$sqlQuery = combine_query($eloquentQuery->toSql(), $eloquentQuery->getBindings());
curtissaunders/laravel-helpers 适用场景与选型建议
curtissaunders/laravel-helpers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 731 次下载、GitHub Stars 达 6, 最近一次更新时间为 2017 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「helpers」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 curtissaunders/laravel-helpers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 curtissaunders/laravel-helpers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 curtissaunders/laravel-helpers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HTML and form generation
Falsy helps you manage half-truths with PHP
Alfabank REST API integration
To Backend with Laravel
A rails-inspired form builder for PHP
IfthenPay PHP helper classes.
统计信息
- 总下载量: 731
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-17