Performance: Route naming
Route naming affects server-side routing resolution speed and maintainability, indirectly impacting page load speed by enabling efficient URL generation and caching.
Route::get('/user/profile', function () { /* ... */ })->name('profile'); // Generating URL by route name $url = route('profile');
Route::get('/user/profile', function () { /* ... */ }); // Generating URL by hardcoding path $url = url('/user/profile');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Hardcoded URLs | 0 (server-side only) | 0 | 0 | [X] Bad |
| Named Routes with caching | 0 (server-side only) | 0 | 0 | [OK] Good |
->name('routeName')?->name('name') method chained after route definition to assign a name.->name('home') after the route definition.Route::get('/profile', function () { return 'User Profile'; })->name('profile');route('profile') return?route() helper returns the URL for the named route 'profile'.route('profile') returns '/profile'.Route::post('/submit', 'SubmitController@store')->name = 'submit.form';->name('name'), not by assignment.->name = 'submit.form', which is invalid syntax; it should be ->name('submit.form').Route::get('/user/{id}', 'UserController@show')->name('user.show');
Route::get('/user/profile', 'UserController@profile')->name('user.profile');route('user.show', ['id' => 'profile']) return?Pass the test and this pattern moves unknown