PHPackages                             jaybizzle/route-binder - 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. jaybizzle/route-binder

ActiveLibrary[Framework](/categories/framework)

jaybizzle/route-binder
======================

Laravel route binding, done right.

4.4.0(3y ago)011.7k1MITPHPPHP &gt;=5.6

Since Jan 29Pushed 3y agoCompare

[ Source](https://github.com/JayBizzle/route-binder)[ Packagist](https://packagist.org/packages/jaybizzle/route-binder)[ RSS](/packages/jaybizzle-route-binder/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (4)Dependencies (7)Versions (15)Used By (0)

Route Binder
============

[](#route-binder)

Laravel route binding, done right.

[![Build Status](https://camo.githubusercontent.com/d2704ed955a2a410af5ecd0c56edb1a86ff0a8f40327dd8d4aa140e0fe0ff791/68747470733a2f2f7472617669732d63692e6f72672f4c61726176656c42412f726f7574652d62696e6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/LaravelBA/route-binder)

Laravel 4 or 5?
---------------

[](#laravel-4-or-5)

The *master* branch holds code compatible with Laravel 5. Releases for Laravel 5 start from the 3.0 tag.

For the Laravel 4 compatible release, go to [the laravel4 branch](https://github.com/LaravelBA/route-binder/tree/laravel4).

The problem
-----------

[](#the-problem)

Projects start simple: a few routes, maybe some resource controllers, and maybe some parameter binding here and there. But soon, the `routes.php` file starts to pile up, spawning hundreds of lines, with complex nested groups and filters or even (god forbid) having calls to `App::make`. Even more cumbersome, having to scroll all those lines searching for that odd route name that you clearly forget because, who remembers those anyway?

This package helps you with (at least) three things:

1. It makes your routes part of your *Application* by [letting you use DI through the IoC container](#ioc)
2. It lets you split up routes in multiple files (classes) without the need for old-fashioned `includes` or `requires`
3. As you'll be creating classes, you have an opportunity to declare some string constants and hold references to those nasty route names

The solution
------------

[](#the-solution)

This package is just two contracts, a config file and a `ServiceProvider`.

As usual, include the `ServiceProvider` in your `config/app.php` file like so:

```
'providers' => [
    // ...
    LaravelBA\RouteBinder\RouteBinderServiceProvider::class,
    // ...
]
```

Then, publish the package's configuration:

```
php artisan vendor:publish --provider="LaravelBA\RouteBinder\RouteBinderServiceProvider"
```

Afterwards, you'll need to create some classes that implement either the `LaravelBA\RouteBinder\Routes` interface, the `LaravelBA\RouteBinder\Bindings` interface or both. Don't panic! You'll see it's a piece of cake:

```
namespace App\Http\Routes;

use Illuminate\Contracts\Routing\Registrar;
use Illuminate\Routing\Router;
use LaravelBA\RouteBinder\Bindings;
use LaravelBA\RouteBinder\Routes;

class FooRoutes implements Routes, Bindings
{
    /**
     * This is what I meant with #3 up there.
     * Completely optional, but highly recommended.
     */
    const INDEX = 'foo.index';

    /**
     * This one is required if you implement the Bindings interface
     */
    public function addBindings(Router $router)
    {
        $router->bind('user_id', function(){
            // Fetch your User object here!
        });
    }

    /**
     * This one is required if you implement the Routes interface
     */
    public function addRoutes(Registrar $router)
    {
        $router->get('foo', ['as' => self::INDEX, 'uses' => function(){
            return view('hello');
        }]);
    }
}
```

And add them to the published config file (you find it now in `config/routes.php`):

```
return [
    'binders' => [
        App\Http\Routes\FooRoutes::class,
        App\Http\Routes\BarRoutes::class,
        App\Http\Routes\BazRoutes::class,
        App\Http\Routes\AwesomeRoutes::class,
    ]
];
```

And you're done! Now all your routes are nicely organized, and if things get out of hand, you can always split 'em up more!

 The IoC Container
-------------------------------------------------

[](#-the-ioc-container)

I love Laravel's Route model binding functionality. I must confess though, I don't use Eloquent, so I always go for the `Route::bind()` option.

But this feature, as powerful as it may be, is pretty nasty on your architecture. Having calls to the DB on the `routes.php` file is awful, and going `App::make(SomeRepository::class)` does not look that much better either.

With this little package, your `Bindings` objects can depend on any `Service` or `Repository` layer of your application. Now, you could even test those bindings by mocking the dependencies and expecting a call to whatever `Repository::find()` method you use on route resolution!

This may look like *waaaaaay* too complicated a scenario right now, but trust me, you'll love it.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 71% 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 ~245 days

Recently: every ~516 days

Total

13

Last Release

1178d ago

Major Versions

1.0.1 → 2.0.02015-02-04

2.0.1 → 3.0.02015-02-12

3.0.0 → 4.0.02015-09-14

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/340752?v=4)[Mark Beech](/maintainers/JayBizzle)[@JayBizzle](https://github.com/JayBizzle)

---

Top Contributors

[![guiwoda](https://avatars.githubusercontent.com/u/1625545?v=4)](https://github.com/guiwoda "guiwoda (22 commits)")[![JayBizzle](https://avatars.githubusercontent.com/u/340752?v=4)](https://github.com/JayBizzle "JayBizzle (7 commits)")[![GC-Max](https://avatars.githubusercontent.com/u/10233281?v=4)](https://github.com/GC-Max "GC-Max (1 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/jaybizzle-route-binder/health.svg)

```
[![Health](https://phpackages.com/badges/jaybizzle-route-binder/health.svg)](https://phpackages.com/packages/jaybizzle-route-binder)
```

###  Alternatives

[laravel/socialite

Laravel wrapper around OAuth 1 &amp; OAuth 2 libraries.

5.7k96.9M674](/packages/laravel-socialite)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[laravel/passport

Laravel Passport provides OAuth2 server support to Laravel.

3.4k85.0M532](/packages/laravel-passport)[laravel/sail

Docker files for running a basic Laravel application.

1.9k186.9M1.0k](/packages/laravel-sail)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)

PHPackages © 2026

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