Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Merklin's avatar

Route Label: Add Labels and Blade @routeLink Support to Laravel Routes

Hi everyone! Hi all.

I just released a small Laravel package that makes it easy to add human-readable labels to your routes and use them in Blade views. It also provides a convenient @routeLink Blade directive for generating links.

Often, when building navigation menus or breadcrumbs, you want a human-readable label for a route without repeating strings or relying only on translation files. This package keeps your route names and labels in one place and makes generating links clean and readable.

Features

  • Add labels to your named routes:
Route::get('/', function () {
    return view('welcome');
})->name('home')->label('Home');
  • Retrieve the label anywhere in your app: {{ routeLabel('home') }} {{-- returns 'Home' --}}

  • Blade directive for quick links: @routeLink('home') {{-- compiles to <a href="...">Home</a> --}}

  • Fallback: if no label is defined, routeLabel() returns the route name.

Any feedback is welcome.

Link: https://packagist.org/packages/milenmk/laravel-route-label

1 like
8 replies
vincent15000's avatar

Interesting effectively ... what do you propose if there are various situations :

  • desktop menu : the label and an icon (label on the right of the icon or perhaps also label under the icon)

  • mobile menu : only an icon

Tray2's avatar

Congratz to releasing your first package.

I personally don't really see the need of it, I would if needed just create a blade component for this. There might however, be others that might want to use it.

 <x-link :url="route('about')">About</x-link>
@props(['url'])
<a href="{{ $url }}">
    {{ $slot }}
</a>
1 like
vincent15000's avatar

I also create a blade component for doing this.

I think that this package could be useful if it provides some other functionalities like identifying the routes that have to be in the menu.

I have a VueJS router with meta data like :

  • icon :'fa-solid fa-home'

  • label: 'Home',

  • mainmenu : true

  • auth : false

  • admin : false

And then I generate the menu automatically from the routes list.

Merklin's avatar

The main benefit is a single source of truth for both the route name and its display label, and easier maintenance: changing a label in one place updates all links.

With this, there is no need for a blade component or any other component. Just define your route like Route::get()->name('route_name')->label('route_label') and then in blade just use @routeLink('route_name').

As for the label, you can also set a translatable string __('Label') or translation key __('route.home')

1 like
Tray2's avatar

Single source of truth is always a good idea, I just don't see the scenario where I want to use the same link in multiple places. If I need to say have a login link in multiple places, then I'd just create a blade component for it.

I'm not saying that your package isn't good, I'm just saying that I would most likely not use it.

2 likes
vincent15000's avatar

You are talking about your package, but can you show it to us ?

Do you have a github repo with it ?

1 like
Merklin's avatar

Sorry, I've missed that. I've updated the first post with the link.

1 like
Merklin's avatar

@vincent15000 I have updated the package, so now you can add custom classes and directives like this:

{{-- With CSS classes --}}
@routeLink('users.index', ['class' => 'btn btn-primary'])

{{-- With Livewire navigation --}}
@routeLink('users.index', ['class' => 'nav-link', 'wire:navigate' => true])

{{-- With Alpine.js directives --}}
@routeLink('users.index', [
    'class' => 'menu-item',
    'x-data' => '{ open: false }',
    'x-show' => 'open',
    '@click' => 'open = !open'
])

{{-- With data attributes --}}
@routeLink('users.index', [
    'class' => 'dropdown-item',
    'data-toggle' => 'modal',
    'data-target' => '#userModal'
])

Or, create more complex links with the block directive:

{{-- With images and complex content --}}
@routeLinkStart('home', ['class' => 'logo-link', 'wire:navigate' => true])
    <img class="logo" src="{{ asset('images/logo.png') }}" alt="Logo" />
    <span class="brand-name">{{ config('app.name') }}</span>
@routeLinkEnd

{{-- With Alpine.js interactions --}}
@routeLinkStart('profile', [
    'class' => 'profile-link',
    'x-data' => '{ open: false }',
    '@click' => 'open = !open'
])
    <img class="avatar" src="{{ $user->avatar }}" alt="Profile" />
    <span class="name">{{ $user->name }}</span>
    <svg class="dropdown-icon" :class="open ? 'rotate-180' : ''">...</svg>
@routeLinkEnd
1 like

Please or to participate in this conversation.