intervention/eloquent-hashid 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

intervention/eloquent-hashid

Composer 安装命令:

composer require intervention/eloquent-hashid

包简介

Configurable HashId Trait for Laravel Eloquent models

README 文档

README

Latest Version

This package provides a trait to easily encode and decode hashids in your Eloquent models. Every model gets an attribute and a scope for hashid queries.

Installation

You can install this package with Composer.

Require the package via Composer:

$ composer require intervention/eloquent-hashid

Laravel will automatically discover the packages service provider class.

Setup

After installation you're able to publish the configuration file to your Laravel application with the following command.

$ php artisan vendor:publish --provider="Intervention\EloquentHashid\Laravel\EloquentHashidServiceProvider"

You will find a new config file in config/hashid.php, which you can customize. I strongly suggest to change at least the salt_prefix option to your own value.

Now you can include the trait Intervention\EloquentHashid\HasHashid in your Eloquent Model to add the hashid features.

use Intervention\EloquentHashid\HasHashid;

class Item extends Model
{
    use HasHashid;
}

Usage

Code Example

Every Eloquent Model gets a new hashid attribute, which is created based on the models classname, the key and the salt prefix. You're also able to query models with the now added hashid() scope.

Access hashid attribute

$item = App\Models\Item::find(123);

// access hashid attribute
$hashid = $item->hashid

Query models

// query model with scope
$item = App\Models\Item::hashid('Ma93ka')->firstOrFail();

// scope can also select multiple items by array
$item = App\Models\Item::hashid(['Ma93ka', 'Op92ae'])->get();

// scope query in one call
$item = App\Models\Item::findByHashid('Ma93ka');

// scope query in one call, throw exception if no model was found
$item = App\Models\Item::findByHashidOrFail('Ma93ka');

Route Model Binding

Eloquent models can be resolved by their hashid in routes by defining a custom key.

use App\Models\Item;

Route::get('/items/{item:hashid}', function (Item $item) {
    return $item;
});

Authors

This library is developed and maintained by Oliver Vogel

License

Intervention Eloquent HashID is licensed under the MIT License.

intervention/eloquent-hashid 适用场景与选型建议

intervention/eloquent-hashid 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 875 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「eloquent」 「hashid」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 intervention/eloquent-hashid 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 intervention/eloquent-hashid 我们能提供哪些服务?
定制开发 / 二次开发

基于 intervention/eloquent-hashid 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 875
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-02-13