WebbieWorks's avatar

Which Route is better?

Hey all, I am learning Laravel and I have seen the routes coded in 2 different ways and was wondering which one is better (easier) for an ecommerce site?

Route::get('/used-equipment.php', 'UsedController@index')->name('usedequipment.index');

or

Route::get('/used-equipment.php', [
    'uses' => 'ProductController@usedCategoryList',
    'as' => 'categories.usedequipment',
]);
0 likes
3 replies
jlrdw's avatar

A lot of that is personal preference and complexity of the application. And how you like to personally name things.

Me for example I just prefer the regular routes.

Cronix's avatar

The way you wrote them, they are functionally identical, so it comes down to preference. There are more ways to use the 2nd way though, than the first. For instance route grouping.

goldtaste's avatar

Ahh, haven't seen the second type before. Sounds like - from above - either will work.

Do you know that you don't need to add the .php extension to your route?

You have

Route::get('/used-equipment.php', 'UsedController@index')->name('usedequipment.index');

In your browser you would go to: https://mysite.com/used-equipment.php

If you do:

Route::get('/used-equipment', 'UsedController@index')->name('usedequipment.index');

In your browser the following would work: https://mysite.com/used-equipment

Most people don't include the extension these days for urls.

Please or to participate in this conversation.