PHPackages                             milenmk/laravel-route-label - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. milenmk/laravel-route-label

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

milenmk/laravel-route-label
===========================

Add label support to Laravel routes with routeLabel() helper and Blade @routeLink directive

1.4.0(1mo ago)012MITPHPPHP ^8.3|^8.4

Since Sep 11Pushed 1mo agoCompare

[ Source](https://github.com/milenmk/laravel-route-label)[ Packagist](https://packagist.org/packages/milenmk/laravel-route-label)[ RSS](/packages/milenmk-laravel-route-label/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (18)Versions (10)Used By (0)

Laravel Route Label
===================

[](#laravel-route-label)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4cda63af9e69a5c1bd89ebc6742346dd1b46f5d4fc756cb12a00b8bcf9dd0ede/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c656e6d6b2f6c61726176656c2d726f7574652d6c6162656c2e7376673f7374796c653d666c6174)](https://packagist.org/packages/milenmk/laravel-route-label)[![Total Downloads](https://camo.githubusercontent.com/c66286d3412f7a52043357b4ee9b54c51534fa55b150a291815d8088f215187e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d696c656e6d6b2f6c61726176656c2d726f7574652d6c6162656c2e7376673f7374796c653d666c6174)](https://packagist.org/packages/milenmk/laravel-route-label)[![GitHub User's stars](https://camo.githubusercontent.com/83739b122e9129b338b94b5ba49cc3b42cf0bacfe32c9aadfaf822e3da258afc/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6d696c656e6d6b2f6c61726176656c2d726f7574652d6c6162656c)](https://github.com/milenmk/laravel-route-label)[![Laravel 10 Support](https://camo.githubusercontent.com/0b7f902482de7d3663b7aa6b87b7caca6e7b3fed489112e6f65f79f4514e60de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302e7825374331312e7825374331322e782d6f72616e67653f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs)[![PHP Version Support](https://camo.githubusercontent.com/4ebacaf442eb732fadc866ded2e1eeff3433a6ae5525762fd89a4b865c2041b1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d696c656e6d6b2f6c61726176656c2d726f7574652d6c6162656c3f7374796c653d666c6174)](https://www.php.net)[![License](https://camo.githubusercontent.com/0b6a7c021892519251d57b4fa7cf214b80ebf4fe64f8f8d8531e6bb08e4d761f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d696c656e6d6b2f6c61726176656c2d726f7574652d6c6162656c2e7376673f7374796c653d666c6174)](https://github.com/milenmk/laravel-route-label/blob/main/LICENSE)[![Contributions Welcome](https://camo.githubusercontent.com/9e93e892d0685e1bf7a1d0bd7c8410d6ecf2086a0a7b48dd58a6b96fa556ea2a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f6e747269627574696f6e732d77656c636f6d652d627269676874677265656e2e7376673f7374796c653d666c6174)](https://github.com/milenmk/laravel-route-label/issues)[![Sponsor me](https://camo.githubusercontent.com/2aff1b5ae52a46452f3284b52645e299f456561d4dfd9b4d20d0a00a8351a123/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d2545322539442541342d6666363962343f7374796c653d666c6174)](https://www.patreon.com/c/LaravelAddonsbyMilen)

A tiny Laravel package that lets you attach human‑friendly labels to your routes and use them in views via a helper or a Blade directive.

- **Route macro**: `->label('My Label')` (supports string‑backed Enums)
- **Localizing the label** You can also pass a translatable string `->label(__('MyLabel'))` or key `->label(__('routes.home'))` for a label
- **Helper**: `routeLabel('route.name')` → label or route name fallback
- **Blade directive**: `@routeLink('route.name')` → `Label`
- **Extended Blade directive**: `@routeLink('route.name', ['class' => 'btn', 'wire:navigate' => true])` → enhanced `` tag with custom attributes
- **Block Blade directives**: `@routeLinkStart('route.name', ['attributes'])` ... `@routeLinkEnd` → for complex link content
- **Blade component**: ``

Requirements
------------

[](#requirements)

- **PHP**: 8.3, 8.4
- **Laravel**: 10.x, 11.x, 12.x, 13.x (Illuminate Support/View/Routing)

Installation
------------

[](#installation)

```
composer require milenmk/laravel-route-label
```

No further setup is needed (package discovery enabled).

Quick Start
-----------

[](#quick-start)

### 1) Define routes with labels

[](#1-define-routes-with-labels)

```
use Illuminate\Support\Facades\Route;

// Simple string label
Route::get('/users', [UserController::class, 'index'])
    ->name('users.index')
    ->label('Users');

// Dynamic label via closure
Route::get('/users/{user}/edit', [UserController::class, 'edit'])
    ->name('users.edit')
    ->label(fn($params) => "Edit {$params['user']->name}");

// Translation key
Route::get('/home', [HomeController::class, 'index'])
    ->name('home')
    ->label('trans:routes.home');

// String-backed Enum
enum RouteLabel: string { case Users = 'Users'; }
Route::get('/users', [UserController::class, 'index'])
    ->name('users.index')
    ->label(RouteLabel::Users);
```

> You must call `->name()` before `->label()`.

### 2) Use the label in Blade

[](#2-use-the-label-in-blade)

#### Using the helper

[](#using-the-helper)

```
{{ routeLabel('users.index') }}
{{ routeLabel('users.edit', ['user' => $user]) }}

```

Renders

```
Users
Edit John
```

#### Using Blade directives

[](#using-blade-directives)

1. Simple directive

    ```
    @routeLink('users.index')
    ```

    Renders:

    ```
    Users
    ```
2. With additional attributes

    ```
    @routeLink('users.index', ['class' => 'btn btn-primary', 'wire:navigate' => true])
    ```

    Renders:

    ```
    Users
    ```
3. With Alpine.js / complex attributes

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

    Renders:

    ```
    Users
    ```

#### Block directives for complex content

[](#block-directives-for-complex-content)

```
@routeLinkStart('home', ['class' => 'logo-link', 'wire:navigate' => true])

    {{ config('app.name') }}
@routeLinkEnd
```

Renders

```

    My App

```

Another example with Alpine.js

```
@routeLinkStart('profile', [
    'class' => 'profile-link',
    'x-data' => '{ open: false }',
    '@click' => 'open = !open'
])

    {{ $user->name }}
    ...
@routeLinkEnd
```

Renders

```

    John Doe
    ...

```

### 3) Using the Blade component

[](#3-using-the-blade-component)

```

```

Renders

```
Users
Edit John
Homepage
Users
```

> Boolean attributes (like `wire:navigate`) are added as attribute names only when set to `true`.
>
> HTML is escaped by default, configurable via `config/route-label.php`.
>
> Fallbacks: if a route has no label, the route name is used (`missing_label_behavior`).

Enum Support
------------

[](#enum-support)

You can use string-backed Enums for labels:

```
enum RouteLabel: string { case Users = 'Users'; }

Route::get('/users', [UserController::class, 'index'])
    ->name('users.index')
    ->label(RouteLabel::Users);
```

For route names (Laravel expects a string), pass the enum value:

```
enum RouteName: string { case UsersIndex = 'users.index'; }

Route::get('/users', [UserController::class, 'index'])
    ->name(RouteName::UsersIndex->value)
    ->label('Users');
```

> The `@routeLink()` directive expects a string route name (not an Enum), because it internally calls `route()`.

Helper Reference
----------------

[](#helper-reference)

- **`routeLabel(string|BackedEnum $name): ?string`**
    - Returns the route label if set.
    - Returns the route name when no label is set.
    - Returns `null` if the route does not exist.

Usage examples:

```
routeLabel('users.index');             // "Users" (if labeled), otherwise "users.index"
routeLabel(RouteName::UsersIndex);     // Works with string-backed Enum
```

In Blade:

```
{{ routeLabel('users.index') ?? 'Unknown route' }}
```

Configuration (Optional / Advanced)
-----------------------------------

[](#configuration-optional--advanced)

Publish the config to customize defaults:

```
php artisan vendor:publish --tag=route-label-config
```

- **default\_link\_class** → default CSS class for the Blade component
- **escape\_html** → whether labels are escaped (true by default)
- **missing\_label\_behavior** → controls fallback when a label is missing

> Basic usage does not require publishing the config.

Errors and Edge Cases
---------------------

[](#errors-and-edge-cases)

- **Calling `->label()` before `->name()`** will throw a `LogicException`.
- **Passing a non string‑backed Enum** to `->label()` will throw an `InvalidArgumentException`.
- **Unknown routes**: `routeLabel()` returns `null` → use the null coalescing operator to provide a fallback.

Why use route labels?
---------------------

[](#why-use-route-labels)

- **Consistency**: keep link texts centralized alongside routes.
- **Localization friendly**: prepare for i18n by mapping names to labels.
- **Cleaner views**: no more hard‑coded strings scattered in templates.
- **Dynamic content**: closures allow runtime-generated labels (e.g., usernames).

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for recent changes.

Contributing
------------

[](#contributing)

- Pull requests and issues are welcome at [GitHub](https://github.com/milenmk/laravel-route-label).
- Follow PSR‑12 requirements

Support My Work
---------------

[](#support-my-work)

If this package saves you time, you can support ongoing development:
👉 [Become a Patron](https://www.patreon.com/c/LaravelAddonsbyMilen)

Other Packages
--------------

[](#other-packages)

Check out my other Laravel packages:

- **[Laravel GDPR Cookie Manager](https://packagist.org/packages/milenmk/laravel-gdpr-cookie-manager)** - GDPR-compliant cookie consent management with user preference tracking
- **[Laravel Email Change Confirmation](https://packagist.org/packages/milenmk/laravel-email-change-confirmation)** - Secure email change confirmation system
- **[Laravel Blacklist](https://packagist.org/packages/milenmk/laravel-blacklist)** - A Laravel package for blacklist validation of user input
- **[Laravel GDPR Exporter](https://packagist.org/packages/milenmk/laravel-gdpr-exporter)** - GDPR-compliant data export functionality
- **[Laravel Locations](https://packagist.org/packages/milenmk/laravel-locations)** - Add Countries, Cities, Areas, Languages and Currencies models to your Laravel application
- **[Laravel Rate Limiting](https://packagist.org/packages/milenmk/laravel-rate-limiting)** - Advanced rate limiting capabilities with exponential backoff
- **[Laravel Datatables and Forms](https://packagist.org/packages/milenmk/laravel-simple-datatables-and-forms)** - Easy to use package to create datatables and forms for Livewire components

License
-------

[](#license)

This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Disclaimer
----------

[](#disclaimer)

This package is provided "as is", without warranty of any kind, express or implied, including but not limited to warranties of merchantability, fitness for a particular purpose, or noninfringement. The author(s) make no guarantees regarding the accuracy, reliability, or completeness of the code, and shall not be held liable for any damages or losses arising from its use. Please ensure you thoroughly test this package in your environment before deploying it to production.

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance91

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~62 days

Total

9

Last Release

42d ago

PHP version history (2 changes)1.0.0PHP ^8.2|^8.3|^8.4

1.4.0PHP ^8.3|^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4587305?v=4)[Milen Karaganski](/maintainers/milenmk)[@milenmk](https://github.com/milenmk)

---

Top Contributors

[![milenmk](https://avatars.githubusercontent.com/u/4587305?v=4)](https://github.com/milenmk "milenmk (16 commits)")

---

Tags

laravellaravel-packagelaravel-routelaravel-routes

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/milenmk-laravel-route-label/health.svg)

```
[![Health](https://phpackages.com/badges/milenmk-laravel-route-label/health.svg)](https://phpackages.com/packages/milenmk-laravel-route-label)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M147](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[hasinhayder/tyro-dashboard

Tyro Dashboard - Beautiful admin dashboard for managing Tyro roles, privileges, users, and settings

5443.8k](/packages/hasinhayder-tyro-dashboard)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[hasinhayder/tyro-login

Tyro Login - Beautiful, customizable authentication views for Laravel 12 &amp; 13

2464.9k6](/packages/hasinhayder-tyro-login)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
