I have setup a route like this:
Route::get('/prod/{id}/{title?}', 'Web\GetItemController@getItem')->where('id', '[0-9]+')->name('prod.item');
This is to retrieve a item based on the id
the title
is only a optional parameter in order to make the url look somewhat nicer.
Then in the controller I fetch the item like this:
class GetItemController extends Controller
{
public function getItem($id, $title = null)
{
$item = new product();
$data = $item->getProdInfo($id);
// Show view with data...
}
}
So I should be able to fetch the item with or without the title
parameter.
So a call like this would trigger the route "https://www.x.com/prod/3/sonic-free-games"
But is there any difference in performance using slug like I do above?
/prod/{id}/{title?}
vs /prod/{id}