0

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}

Kiow
  • 870
  • 4
  • 18
  • 32
  • 2
    If there are, its minuscule and as an effect of the framework parsing an extra URL parameter. Try not to worry too much about micro-optimizations. One thing to watch out for is character limit, though. – Derek Pollard Jun 20 '18 at 16:48
  • 1
    @Derek what do you mean by character limit? – Kiow Jun 20 '18 at 17:02
  • I could never do this topic justice in a single comment, but this answer definitely does: https://stackoverflow.com/a/417184/2020002 – Derek Pollard Jun 20 '18 at 17:07
  • @Derek thanks for the link! Guess I dont have to worry about that either since my title never exceeds 40 chars – Kiow Jun 20 '18 at 18:13

0 Answers0