Laravel HashSlug 项目教程
2024-08-27 03:00:21作者:庞眉杨Will
1、项目的目录结构及介绍
Laravel HashSlug 项目的目录结构如下:
laravel-hashslug/
├── config/
│ └── hashslug.php
├── src/
│ ├── HashSlug.php
│ └── HashSlugServiceProvider.php
├── tests/
│ └── HashSlugTest.php
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── composer.lock
└── phpunit.xml
目录结构介绍
config/:包含项目的配置文件hashslug.php。src/:包含项目的主要源代码文件,包括HashSlug.php和HashSlugServiceProvider.php。tests/:包含项目的测试文件HashSlugTest.php。.gitignore:Git 忽略文件。LICENSE:项目的许可证文件。README.md:项目的说明文档。composer.json和composer.lock:Composer 依赖管理文件。phpunit.xml:PHPUnit 测试配置文件。
2、项目的启动文件介绍
项目的启动文件主要包括 HashSlugServiceProvider.php 和 HashSlug.php。
HashSlugServiceProvider.php
HashSlugServiceProvider.php 是 Laravel 服务提供者文件,负责注册和启动 HashSlug 服务。
namespace Afiqiqmal\LaraHashSlug;
use Illuminate\Support\ServiceProvider;
class HashSlugServiceProvider extends ServiceProvider
{
public function boot()
{
$this->publishes([
__DIR__.'/../config/hashslug.php' => config_path('hashslug.php'),
]);
}
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../config/hashslug.php', 'hashslug'
);
}
}
HashSlug.php
HashSlug.php 是 HashSlug 的核心逻辑文件,负责生成和解析 HashSlug。
namespace Afiqiqmal\LaraHashSlug;
use Hashids\Hashids;
class HashSlug
{
protected $hashids;
public function __construct()
{
$this->hashids = new Hashids(
config('hashslug.salt'),
config('hashslug.length'),
config('hashslug.alphabet')
);
}
public function encode($id)
{
return $this->hashids->encode($id);
}
public function decode($hash)
{
$decoded = $this->hashids->decode($hash);
return $decoded ? $decoded[0] : null;
}
}
3、项目的配置文件介绍
项目的配置文件位于 config/hashslug.php,包含了 HashSlug 的默认配置。
hashslug.php
return [
'salt' => env('HASHID_SALT', 'lara-hash-slug'),
'length' => env('HASHID_LENGTH', 12),
'alphabet' => env('HASHID_ALPHABET', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'),
'unique' => env('HASHID_UNIQUE', true),
];
配置项介绍
salt:用于生成 HashSlug 的盐值,默认值为lara-hash-slug。length:生成的 HashSlug 的长度,默认值为 12。alphabet:用于生成 HashSlug 的字符集,默认值为abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890。unique:是否生成唯一的 HashSlug,默认值为true。
通过以上配置,可以灵活地调整 HashSlug 的生成规则。
登录后查看全文
热门项目推荐
kernelopenEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。C081
baihu-dataset异构数据集“白虎”正式开源——首批开放10w+条真实机器人动作数据,构建具身智能标准化训练基座。00
mindquantumMindQuantum is a general software library supporting the development of applications for quantum computation.Python056
PaddleOCR-VLPaddleOCR-VL 是一款顶尖且资源高效的文档解析专用模型。其核心组件为 PaddleOCR-VL-0.9B,这是一款精简却功能强大的视觉语言模型(VLM)。该模型融合了 NaViT 风格的动态分辨率视觉编码器与 ERNIE-4.5-0.3B 语言模型,可实现精准的元素识别。Python00
GLM-4.7GLM-4.7上线并开源。新版本面向Coding场景强化了编码能力、长程任务规划与工具协同,并在多项主流公开基准测试中取得开源模型中的领先表现。 目前,GLM-4.7已通过BigModel.cn提供API,并在z.ai全栈开发模式中上线Skills模块,支持多模态任务的统一规划与协作。Jinja00
agent-studioopenJiuwen agent-studio提供零码、低码可视化开发和工作流编排,模型、知识库、插件等各资源管理能力TSX0135
Spark-Formalizer-X1-7BSpark-Formalizer 是由科大讯飞团队开发的专用大型语言模型,专注于数学自动形式化任务。该模型擅长将自然语言数学问题转化为精确的 Lean4 形式化语句,在形式化语句生成方面达到了业界领先水平。Python00
项目优选
收起
deepin linux kernel
C
27
11
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
465
3.46 K
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
200
81
暂无简介
Dart
715
172
Ascend Extension for PyTorch
Python
274
311
React Native鸿蒙化仓库
JavaScript
285
331
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
846
424
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
10
1
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.26 K
693
华为昇腾面向大规模分布式训练的多模态大模型套件,支撑多模态生成、多模态理解。
Python
107
120