Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

extjac's avatar

Route model implicit binding with two custom Key

my route looks like this,

Route::get('/items/{item:uuid}/bookings/{booking:uuid}', 'ItemBookingController@show');

and my controller looks like this

public function show( \App\Item $item, \App\Booking $booking )
{
    return 'ok'; //
}

and i get a 404.

can I nest two custom route like above?

0 likes
7 replies
Sinnbeck's avatar

How does the url look when you call it?

martinbean's avatar

@extjac Yes, it should work. So either you’re passing incorrect UUIDs, or the booking doesn’t belong to the item.

extjac's avatar

In the relationships, the the item hasMany bookings or the booking belongsTo the iteam.

Sinnbeck's avatar

And both items exist in the database with that uuid?

Sinnbeck's avatar

Btw. If it belongs to the item, why not just pass in the booking? That way your urls doesn't get "stale" if the item changes

Route::get('/items/bookings/{booking:uuid}', 'ItemBookingController@show');

public function show(\App\Booking $booking )
{
    $item = $booking->item;
    return 'ok'; //
}
extjac's avatar

it works if I remove the second binding

public function show( \App\Item $item,  $booking )
{
    return 'ok'; //
}

So the controller look like this

public function show( \App\Item $item,  $booking )
{
   	\App\Booking::where('uuid', $booking)->firstOrFail();

 	return 'ok'; 
}

i guess i will use it like this....

Please or to participate in this conversation.