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',
]);
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.
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.
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 sign in or create an account to participate in this conversation.