abdelhamiderrahmouni/self-healing-urls
Composer 安装命令:
composer require abdelhamiderrahmouni/self-healing-urls
包简介
README 文档
README
Self Healing URLs is a simple Laravel package inspired by this video from Aaron Francis.
It allows you to mark Eloquent models as self-healing so that the URLs generated for said models can include an SEO friendly slug whilst not breaking should the slug alter in any way.
See the Original package at: lukeraymonddowning/self-healing-urls
I forked it to use it with my laravel 12 projects.
Installation
The package can be installed via Composer:
composer require abdelhamiderrahmouni/self-healing-urls
Once installed, add the HasSelfHealingUrls trait to any Eloquent model:
use AbdelhamidErrahmouni\SelfHealingUrls\Concerns\HasSelfHealingUrls; class Post extends Model { use HasSelfHealingUrls; }
If your model has a column named slug, you're all set. Otherwise, define
a $slug property on your model to inform the package which column to use instead:
use AbdelhamidErrahmouni\SelfHealingUrls\Concerns\HasSelfHealingUrls; class Post extends Model { use HasSelfHealingUrls; protected $slug = 'title'; }
Don't worry if your "slug" isn't URL friendly; the package will take care of formatting it for you. In fact, it doesn't even have to be unique because the defined unique identifier for your model will also be included at the end.
Limitations
By default, the package requires that your unique identifier (such as the id or uuid column)
not have any - characters. You can implement your own IdentifierHandler as detailed in the next section.
Unless you implement a custom Rerouter, the package requires that you have
defined names to the routes you want to use with self healing URLs.
Using a custom IdentifierHandler
If you need to customize how a slug is joined to a model identifier (which by default is just a hyphen),
you can create your own class implementing IdentifierHandler and register it in the register
method of your AppServiceProvider.
Here is an example using an _ instead of a hyphen:
class UnderscoreIdentifierHandler implements IdentifierHandler { public function joinToSlug(string $slug, string|int $identifier): string { return "{$slug}_{$identifier}"; } public function separateFromSlug(string $value): string { return Str::afterLast($value, '_'); } }
Register the custom handler in your AppServiceProvider like so:
class AppServiceProvider extends ServiceProvider { public function register(): void { $this->app->singleton(IdentifierHandler::class, UnderscoreIdentifierHandler::class); } }
Attributions
Without Aaron's video, I wouldn't have even thought about this, so props to him. Go watch the video.
abdelhamiderrahmouni/self-healing-urls 适用场景与选型建议
abdelhamiderrahmouni/self-healing-urls 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 abdelhamiderrahmouni/self-healing-urls 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abdelhamiderrahmouni/self-healing-urls 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-25