承接 pfrug/hash-id 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

pfrug/hash-id

最新稳定版本:v1.0.0

Composer 安装命令:

composer require pfrug/hash-id

包简介

Simple trait for Laravel to encode IDs in URLs, providing a secure and obfuscated way to expose model identifiers

README 文档

README

A simple trait for Laravel to encode IDs in URLs, providing a secure and obfuscated way to expose model identifiers.

Installation

To install the package, run the following command:

composer require pfrug/hash-id

Configuration

To publish the configuration file, use:

php artisan vendor:publish --tag="hashid-config"

This will create the hashid.php configuration file in the config directory.

Usage

  1. To use the HashId trait, simply include it in your model:
use Pfrug\HashId;

class Post extends Model
{
    use HashId;
}
  1. Getting the encoded ID in the route

In your route model binding, you can now use the encoded ID:

Route::get('/post/{post}', function (Post $post) {
    return $post;
});

This will automatically encode the id of your model in URLs.

Regenerate Configuration Values

If you want to regenerate the encoding values for prime, inverse, and random, you can use the following command:

php artisan hashid:regenerate

This will update the hashid.php configuration file with new values.

Running Tests

To run the tests for the package, use the following command:

vendor/bin/phpunit --configuration "phpunit.xml" --filter=HashIdTest

License

MIT License

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-20