PHPackages                             tomhart/laravel-route-from-model - 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. [Framework](/categories/framework)
4. /
5. tomhart/laravel-route-from-model

ActiveLibrary[Framework](/categories/framework)

tomhart/laravel-route-from-model
================================

Laravel Route From Model

v1.1.5(6y ago)05[4 PRs](https://github.com/TomHart/laravel-route-from-model/pulls)MITPHPPHP ^7.2

Since Dec 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/TomHart/laravel-route-from-model)[ Packagist](https://packagist.org/packages/tomhart/laravel-route-from-model)[ Docs](https://github.com/)[ RSS](/packages/tomhart-laravel-route-from-model/feed)WikiDiscussions master Synced yesterday

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

Laravel Route From Model
========================

[](#laravel-route-from-model)

[![Build Status](https://camo.githubusercontent.com/eca9a4c26078802029a421b6500fa372aeed69f11c504c25804c23f3dbe09b29/68747470733a2f2f7472617669732d63692e636f6d2f546f6d486172742f6c61726176656c2d726f7574652d66726f6d2d6d6f64656c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/TomHart/laravel-route-from-model)[![codecov](https://camo.githubusercontent.com/055392105a8354a5bfc875aade9fc4c2826ad903eec64a67a0305a81436918a4/68747470733a2f2f636f6465636f762e696f2f67682f546f6d486172742f6c61726176656c2d726f7574652d66726f6d2d6d6f64656c2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/TomHart/laravel-route-from-model)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/47a3cb356c74727cae82d5416dd7369a001a6cf9203d19e5dcc6e9b43e2cb7d2/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f546f6d486172742f6c61726176656c2d726f7574652d66726f6d2d6d6f64656c2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/TomHart/laravel-route-from-model/?branch=master)[![GitHub release (latest by date)](https://camo.githubusercontent.com/018caaffe856fc09ef45bb252ae212b90c46ce39896cb3c807b1d269a57840a6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f546f6d486172742f6c61726176656c2d726f7574652d66726f6d2d6d6f64656c3f636f6c6f723d677265656e)](https://camo.githubusercontent.com/018caaffe856fc09ef45bb252ae212b90c46ce39896cb3c807b1d269a57840a6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f546f6d486172742f6c61726176656c2d726f7574652d66726f6d2d6d6f64656c3f636f6c6f723d677265656e)[![GitHub](https://camo.githubusercontent.com/4f678239c70667bb9b997957657d678cdc0cc722b1fcde96d5308a135896a5da/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f546f6d486172742f6c61726176656c2d726f7574652d66726f6d2d6d6f64656c3f636f6c6f723d677265656e)](https://camo.githubusercontent.com/4f678239c70667bb9b997957657d678cdc0cc722b1fcde96d5308a135896a5da/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f546f6d486172742f6c61726176656c2d726f7574652d66726f6d2d6d6f64656c3f636f6c6f723d677265656e)

This library allows a route to be built just from a `Model` instance, automatically pulling out the parameters, rather than having to manually pass them.

### Simple Example

[](#simple-example)

Imagine a route called `test`:

```
Route::get('/test/{name}')->name('test');
```

Calling:

```
route_from_model('test', SomeModel::find(1));
```

will successfully build the route, as `name` is an attribute on `SomeModel` that can be retrieved.

Now imagine you want to change the route to be:

```
Route::get('/test/{name}/id/{id}/{seo_slug}')->name('test');
```

Using the default route building in Laravel, you'd need to manually go to everywhere the route is built, and specify what/where the extra `id` and `seo_slug` data should come from. Providing they exist on `SomeModel`, using the exact same `route_from_model` call above, it will automatically be able to build the route without you needing to change anything.

### Relationship

[](#relationship)

Using `route_from_model`, you're also able to automatically get data from model relationships too, by using `->`

```
Route::get('/test/{name}/{id}/{parent->relationship->value}/{slug}/{child->value}')->name('test');
```

Providing all those relationships/attributes exist, `route_from_model` will be able to build the URL. And the route will successfully change, as all the extra parts can be extracted from the `Model`.

### Trait

[](#trait)

You can also add the `BuildRouteTrait` to your model, and providing the model has a

```
private $routeName = 'test';
```

property, you can build a route using:

```
$route = $model->buildRoute();
```

### Attributes and static values

[](#attributes-and-static-values)

You can also combine `route_from_model` with static values too. Imagine the route:

```
Route::get('/test/{name}/{static}')->name('test');
```

where static **isn't** an attribute available on `SomeModel`, you can simply pass it an array as the third parameter.

```
route_from_model('test', SomeModel::find(1), ['static' => 'MyValue']);
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

5

Last Release

2345d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1374434?v=4)[Tom Hart](/maintainers/TomHart)[@TomHart](https://github.com/TomHart)

---

Top Contributors

[![tom-hart-sky-uk](https://avatars.githubusercontent.com/u/219799917?v=4)](https://github.com/tom-hart-sky-uk "tom-hart-sky-uk (26 commits)")[![TomHart](https://avatars.githubusercontent.com/u/1374434?v=4)](https://github.com/TomHart "TomHart (3 commits)")

---

Tags

laravelrouterroutingroutetomhart

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tomhart-laravel-route-from-model/health.svg)

```
[![Health](https://phpackages.com/badges/tomhart-laravel-route-from-model/health.svg)](https://phpackages.com/packages/tomhart-laravel-route-from-model)
```

###  Alternatives

[laravel/boost

Laravel Boost accelerates AI-assisted development by providing the essential context and structure that AI needs to generate high-quality, Laravel-specific code.

3.4k10.6M274](/packages/laravel-boost)[laravel/folio

Page based routing for Laravel.

608453.9k27](/packages/laravel-folio)[pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project. Heavily inspired by the Laravel router.

696214.6k17](/packages/pecee-simple-router)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

71510.9M66](/packages/laravel-mcp)[laravel/roster

Detect packages &amp; approaches in use within a Laravel project

15410.4M7](/packages/laravel-roster)[izniburak/router

simple router class for php

23522.6k7](/packages/izniburak-router)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
