PHPackages                             motomedialab/laravel-self-healing-urls - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. motomedialab/laravel-self-healing-urls

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

motomedialab/laravel-self-healing-urls
======================================

Generate self-healing URLs for models

v1.1.1(1y ago)252.7k1MITPHPPHP ^8.1

Since Nov 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/motomedialab/laravel-self-healing-urls)[ Packagist](https://packagist.org/packages/motomedialab/laravel-self-healing-urls)[ Docs](https://github.com/motomedialab/laravel-self-healing-urls)[ RSS](/packages/motomedialab-laravel-self-healing-urls/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (0)

Self-healing URLs in Laravel
============================

[](#self-healing-urls-in-laravel)

This package was inspired [Aaron Francis](https://www.youtube.com/watch?v=a6lnfyES-LA) on YouTube - thanks Aaron! This lightweight package allows you to create URLs that are able to self-heal, regardless of the slug provided.

This is great for SEO purposes, allowing you to change slugs without worrying, and will force a 301 redirect to the correct URL.

This technique is commonly used on well known websites such as Amazon and Medium to allow slugs to change without breaking the actual URL.

An example of this would be visiting `https://your-site.com/posts/old-slug-12345` automatically redirecting you to `https://your-site.com/posts/new-slug-12345`. It does this based on the persisted unique ID at the end of the slug.

This makes use of Laravel's pre-existing route model binding.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require motomedialab/laravel-self-healing-urls
```

Usage
-----

[](#usage)

To use this package, simply install it, apply the provided trait to your model and tell the trait where the models slug can be found.

In the below examples I've used a `Post` model, but this really can apply to any model you like.

```
