Support the ongoing development of Laravel.io →
posted 10 years ago
Requests

I am using the following code in Routes.php to bind multiple parameters (using my own resolution logic). It works ok, but seems a bit clunky. Anyone know of a better way?

Route::bind('cat', function($value)
{
    return \App\Page::where('category', $value)->first();
});
Route::bind('subcat', function($value)
{
    return \App\Page::where('sub_category', $value)->first();
});

Route::get('{cat}/{subcat}', function (App\Page $cat, App\Page $subcat)
{
return dd($subcat);
});
Last updated 2 years ago.
0

....Actually I really need to be able to bind both 'cat' and 'subcat' together in the same Closure, rather than seperately. Otherwise 'subcats' with the same name (but in different 'cats') wont be returned. Anyone know a way to do this?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Bulmer bulmer Joined 5 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.