I'm working on a small TV Show application where I want to have the show name (slug) in the URL.
Currently when I list all the shows the URL to the show is /shows/{show_id}
. That's not really how I want it routed.
Example how I want it to be: /shows/{show_name}
where show_name
is a field on the Show
model.
In my routes.php
I simply use Route::resource('shows','ShowsController');
You'd use a route binding:
Route::bind('show', function($value, $route) {
return Show::where('show_name', $value)
->first();
});
and individual routes:
Route::get('shows/{show}', 'ShowsController@getShow');
I don't believe resource routing can be used in combination with bindings at this time.