PHPackages                             svanthuijl/laravel-routable-models - 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. [API Development](/categories/api)
4. /
5. svanthuijl/laravel-routable-models

ActiveLibrary[API Development](/categories/api)

svanthuijl/laravel-routable-models
==================================

This packages allows you to create eloquent models which have their own routes.

10.0.0(2y ago)04MITPHPPHP ^8.0

Since May 23Pushed 2y ago1 watchersCompare

[ Source](https://github.com/SvanThuijl/laravel-routable-models)[ Packagist](https://packagist.org/packages/svanthuijl/laravel-routable-models)[ RSS](/packages/svanthuijl-laravel-routable-models/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Associate routes with Eloquent models
=====================================

[](#associate-routes-with-eloquent-models)

This packages allows you to create eloquent models which have their own routes. The routes will automatically be generated when the model is saved and the routes will automatically be registered in the router.

### Localized routes

[](#localized-routes)

The package also offers support for localized routes for translatable models. This is built on top of "spatie/laravel-translatable".

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

[](#installation)

This package can be installed through Composer.

```
composer require svanthuijl/laravel-routable-models
```

### Migrations

[](#migrations)

Migrations are automatically loaded. Optionally, you can publish the migrations of this package with this command:

```
php artisan vendor:publish --tag="routable-migrations"
```

### Config

[](#config)

Optionally, you can publish the config file of this package with this command:

```
php artisan vendor:publish --tag="routable-config"
```

The config file was built to be configured with dotenv variables.

```
APP_LOCALE=en # This will set the default locale.
APP_LOCALES=en,nl,de #this will set the available locales separated by a comma.
```

### Service provider

[](#service-provider)

The service provider for this package is not discovered automatically. Register the RoutableServiceProvider manually in your config/app.php service providers section.

**Important!** Make sure that this is the last service provider to be registered since it does check for previously registered routes.

```
    'providers' => ServiceProvider::defaultProviders()->merge([
        /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */

        /*
         * Added last to not be overwritten by application routes...
         */
        Svanthuijl\Routable\RoutableServiceProvider::class,
    ])->toArray(),
```

Using the package
-----------------

[](#using-the-package)

### Implement the package

[](#implement-the-package)

To make a model routable implement the `HasRoutes` interface and use the `InteractsWithRoutes` trait in your model.

```
