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?
How does the url look when you call it?
@extjac Yes, it should work. So either you’re passing incorrect UUIDs, or the booking doesn’t belong to the item.
In the relationships, the the item hasMany bookings or the booking belongsTo the iteam.
And both items exist in the database with that uuid?
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'; //
}
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.