Say I have some routes:
Route::get('items', 'ItemController@index')->name('item.index');
Route::get('items/{hash}/{slug}', 'ItemController@show')->name('item.show');
While using route model binding I want to handle the following cases:
/items/<correct_hash>/<incorrect_slug>
permanent redirect to correct hash and slug/items/<correct_hash>
permanent redirect to correct hash and slug- Anything else redirect to
/items/
I currently understand the shortcut benefit of route model binding which reduces controller code but is typically used for a simple /items/{id}
cases. Is it possible to extend what is shown in the documentation for my case? Or should I scrap the entire model binding approach and go back to caveman controller logic?
Currently it seems the documentation can only bind one parameter at a time not a combination:
Route::bind('user', function ($value) {
return App\User::where('name', $value)->first() ?? abort(404);
});