PHPackages                             neurony/laravel-url - 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. [Database &amp; ORM](/categories/database)
4. /
5. neurony/laravel-url

Abandoned → [varbox/varbox](/?search=varbox%2Fvarbox)ArchivedLibrary[Database &amp; ORM](/categories/database)

neurony/laravel-url
===================

Generate custom URLs for any Eloquent model (Laravel 5.7 and up).

3.0.0(6y ago)32345MITPHPPHP ^7.2

Since Dec 25Pushed 6y ago1 watchersCompare

[ Source](https://github.com/Neurony/laravel-url)[ Packagist](https://packagist.org/packages/neurony/laravel-url)[ RSS](/packages/neurony-laravel-url/feed)WikiDiscussions master Synced yesterday

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

Generate custom URLs for any Eloquent model
===========================================

[](#generate-custom-urls-for-any-eloquent-model)

[![Build Status](https://camo.githubusercontent.com/1cabe6ef11804239e7e24054550ac2efc8cec958a09db85b2870bf4cd9e417dd/68747470733a2f2f7472617669732d63692e6f72672f4e6575726f6e792f6c61726176656c2d75726c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Neurony/laravel-url)[![StyleCI](https://camo.githubusercontent.com/74f440620f7b0005e81f3fc15214600c8881040cfbc28683eacb592615a537a7/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3136323332393532352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/162329525)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/3fa919b5b2922dda6aa4b50bf92e8d89eead23a41f012d82bfe194fc33d10eb2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f4e6575726f6e792f6c61726176656c2d75726c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Neurony/laravel-url/?branch=master)

- [Overview](#overview)
- [Installation](#installation)
- [Usage](#usage)
- [Customisations](#customisations)
- [Extra](#extra)

Overview
========

[](#overview)

This package allows any Eloquent model record to have a custom URL associated to it through a polymorphic one-to-one relationship.

The URL will be automatically saved inside the `urls` table, along with the model using the `created` and `updated` Eloquent events.
When the model is force deleted, the corresponding URL will also be deleted by leveraging the `deleted` Eloquent event.

Installation
============

[](#installation)

Install the package via Composer:

```
composer require neurony/laravel-url

```

Publish the migration file with:

```
php artisan vendor:publish --provider="Neurony\Url\ServiceProvider" --tag="migrations"

```

After the migration has been published you can create the `urls` table by running:

```
php artisan migrate

```

Usage
=====

[](#usage)

### Step 1

[](#step-1)

Insert the following as your **last** line in your `routes/web.php` file:

```
Route::customUrl();

```

This route will catch any URL and will compare it against the `urls` table.
If the URL matches a record in that table, it will dispatch the request to the designated controller and action specified in step 2.

### Step 2

[](#step-2)

Your Eloquent models should use the `Neurony\Url\Traits\HasUrl` trait and the `Neurony\Url\Options\UrlOptions` class.

The trait contains an abstract method `getUrlOptions()` that you must implement yourself.

Here's an example of how to implement the trait:

```
