🎓 A1Learner
🔍
0 of 50 lessons completed

Laravel Named Routes

A named route is a route with a short name of its own. The name lets code point at the route without writing its address.

Name a route

This route is named l08.profile.

Route::get('/l08/profile', fn () => 'Your profile page')->name('l08.profile');

Build its address

route() turns the name into a full address.

route('l08.profile');

Example

<?php

use Illuminate\Support\Facades\Route;

Route::get('/l08/profile', fn () => 'Your profile page')->name('l08.profile');
Route::get('/l08/link', fn () => route('l08.profile'));

Key points

  • Named route: a route with a short name of its own.
  • name() gives a route its name, like ->name('profile').
  • route() builds the address of a named route.
  • A name stays valid when the address changes.
  • Use a name when code links to the route.

In this example, the first lines load the Route helper. The next line adds the profile route and names it l08.profile. The last line adds a route that builds the named route's address.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

Which helper builds the address of a named route?