Route model binding with a custom key per route

getRouteKeyName() changes the binding column for a model everywhere, which is wrong when the admin addresses an order by id and the customer addresses it by reference.

// RouteServiceProvider::boot()
Route::bind('publicOrder', function ($value) {
    return Order::where('reference', $value)->firstOrFail();
});

// routes/web.php
Route::get('/orders/{publicOrder}', 'OrderController@show');
Route::get('/admin/orders/{order}', 'AdminOrderController@show');   // by id

An explicit binding also gives somewhere to add a scope, which the implicit version has no room for — a customer-facing route that must only resolve the current user’s orders belongs here rather than in a controller check that is easy to forget. firstOrFail() preserves the automatic 404; returning null instead produces a confusing error further down.