---
title: "Route model binding — Sluggable for Laravel | Roundly"
description: "Implicit, custom-column, scoped and soft-deleted route binding by slug, locale-aware URLs and an optional primary-key fallback."
url: https://roundly-consulting.com/open-source/docs/sluggable-for-laravel/routing
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Sluggable for Laravel](https://roundly-consulting.com/open-source/docs/sluggable-for-laravel.md)

# Route model binding

```php
Route::get('/topics/{topic}', ShowTopic::class);                              // routeKey() column
Route::get('/posts/{post:seo_slug}', ShowPost::class);                        // any slug column
Route::get('/clinics/{clinic}/products/{product:slug}', ShowProduct::class)->scopeBindings();
Route::get('/archive/{topic}', ShowArchived::class)->withTrashed();
route('topics.show', $topic);                                                 // current-locale slug
```

- routeKey() makes the column getRouteKeyName(); for a locale map getRouteKey() is the current-locale slug, so URL generation depends on the locale — queued URL generation should run under the intended locale.
- Binding follows the definition’s chain (LocaleFallback::Any by default, so a URL in any resolvable locale still resolves) and prefers the current locale.
- Scoped child bindings (->scopeBindings(), HasMany and BelongsToMany) and ->withTrashed() routes are covered.
- Non-string, over-long or control-character values never reach the database.

## Primary-key fallback

```php
SlugDefinition::for('slug')->from('name')->routeKey()->bindByKeyFallback();
// /products/red-chair and /products/42 both resolve
```

bindByKeyFallback() (or binding.key\_fallback globally) tries the primary key after a slug miss — and only for values shaped like the key: ctype\_digit for integer keys, the model’s own uuid/ulid validation for unique ids. A numeric slug like 2024 is never shadowed by id 2024.

## Composing with HasUuids / HasUlids

HasUuids and HasUlids also define resolveRouteBindingQuery, so resolve the conflict with insteadof — HasSlug keeps their malformed-id guard for key bindings:

```php
use HasSlug, HasUuids {
    HasSlug::resolveRouteBindingQuery insteadof HasUuids;
}
```

A method declared on the model class itself silently wins over the trait — delete your own getRouteKeyName() / resolveRouteBinding() when adopting routeKey().

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/sluggable-for-laravel.md)
