Interview Answer:
A named route gives a route a stable application-level name. Instead of hard-coding URLs throughout the application, code can refer to the route by name.
Example:
Route::get('/products', [ProductController::class, 'index'])
->name('products.index');
Then:
return redirect()->route('products.index');
Blade:
<a href="{{ route('products.index') }}">Products</a>
Scenario:
If /products changes to /catalog/products, code using route('products.index') does not need to change. Only the route definition changes.
Named routes are particularly useful for redirects, links, forms, authorization logic, testing, and URL generation.
0 comments:
Post a Comment
Thanks