lanin/laravel-hashids
Composer 安装命令:
composer require lanin/laravel-hashids
包简介
Integrate Hashids with Laravel.
README 文档
README
Easily integrate Laravel with Hashids with full model support.
There are lots of packages for integrating Hashids with Laravel, but all of them just provide you with facade and add some syntax sugar.
But what about model binding and automatic id resolving? This package gives you all. All you have to do is just to install it!
Installation
PHP 5.4+ or HHVM 3.3+, Composer and Laravel 5.0+ are required.
To get the latest version of Laravel Laravel-Hashids, simply install it via composer.
$ composer require lanin/laravel-hashids
Once Laravel-Hashids is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.
Lanin\Laravel\Hashids\HashidsServiceProvider::class,
The last thing is to add \Lanin\Laravel\Hashids\UseHashidsRouter trait to your App\Http\Kernel.
This will force Laravel to use package router to dispatch the route.
namespace App\Http; class Kernel extends HttpKernel { use \Lanin\Laravel\Hashids\UseHashidsRouter; ... }
Also you can register HashidsFacade for easier access to the Hashids methods.
'Hashids' => Lanin\Laravel\Hashids\HashidsFacade::class,
Usage
You don't have to modify anything in your routes or html to make it run. If you are using model bindings and route resolving in html, everything will convert automatically.
Binding
After the installation, Router's method model that binds your placeholders ids to the models will be updated to automatically support hashids and convert them to the internal integer ids.
Routing
If you will pass hash id to the url it will be easily resolved into an associated model. But how replace ids in your html output? There are two ways. Everything depends on how you form your urls.
If you prefer form them by hands, package gives you the Blade helper method @hashids($id) that will convert your id to the hash string.
<a href="/posts/@hashids($post->id)">{{$post->title}}</a>
But this method is tedious. And I prefer using awesome Laravel feature that automatically extracts ids from models and inserts them into your urls. Example:
route('page.show', $page); url('page', ['id' => $page]);
This methods were updated to handle Hashids too. They will automatically replace integer ids from your models to Hashids.
If for some reason you don't want to convert them, just implement
\Lanin\Laravel\Hashids\DoNotUseHashidsinterface in your model.
Configuration
By default package will use your APP_KEY as a salt and 5 symbols length for the hash. If you want to overwrite it, publish hashids configs and edit config/hahshids.php
$ php artisan vendor:publish
Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
lanin/laravel-hashids 适用场景与选型建议
lanin/laravel-hashids 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 392 次下载、GitHub Stars 达 10, 最近一次更新时间为 2015 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「router」 「laravel」 「hashids」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lanin/laravel-hashids 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lanin/laravel-hashids 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lanin/laravel-hashids 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
Router
PMVC App Action Router
Database alias router extension for Nette Framework
Alfabank REST API integration
PHP Router
统计信息
- 总下载量: 392
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-05