Named routes allow you to generate URLs or redirect to routes using their name rather than their URI, making your application easier to maintain.
Route::get('/dashboard', [DashboardController::class, 'index'])->name('dashboard');
Route::get('/profile/{user}', [ProfileController::class, 'show'])->name('profile.show');
// In PHP
$url = route('dashboard'); // https://example.com/dashboard
$url = route('profile.show', ['user' => 42]); // .../profile/42
// In Blade templates
<a href="{{ route('dashboard') }}">Dashboard</a>
<a href="{{ route('profile.show', $user) }}">View Profile</a>
return redirect()->route('dashboard');
return redirect()->route('profile.show', ['user' => $user->id]);
use Illuminate\Support\Facades\Route;
if (Route::currentRouteName() === 'dashboard') {
// active state logic
}
// In Blade
@if (request()->routeIs('dashboard'))
<span class="active">Dashboard</span>
@endif