PHPackages                             creutz/laravel-url-aliases - 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. creutz/laravel-url-aliases

ActiveComposer-package[Utility &amp; Helpers](/categories/utility)

creutz/laravel-url-aliases
==========================

Use url-aliases in Laravel project

01PHP

Since Aug 23Pushed 3y agoCompare

[ Source](https://github.com/creutz/laravel-url-aliases)[ Packagist](https://packagist.org/packages/creutz/laravel-url-aliases)[ RSS](/packages/creutz-laravel-url-aliases/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel URL Aliases
===================

[](#laravel-url-aliases)

[![License](https://camo.githubusercontent.com/fa50a3b3c91097192e37931c525514f376495f25c6ef9b7fe64a7ae9fef783d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f666f6d76617373732f6c61726176656c2d75726c2d616c69617365732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-url-aliases)[![Build Status](https://camo.githubusercontent.com/b2ecc6f0d227a3dd8499aa224e1c46bc1e4efb9be31767154b35c34841e3b3a3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f666f6d76617373732f6c61726176656c2d75726c2d616c69617365732e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/fomvasss/laravel-url-aliases)[![Latest Stable Version](https://camo.githubusercontent.com/5d9067262fd5425ba29d42ce6408ace35ea6146cce6b841bf41ebb8c2ba325ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6d76617373732f6c61726176656c2d75726c2d616c69617365732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-url-aliases)[![Total Downloads](https://camo.githubusercontent.com/6060354539564a4740cd2be42f0d73ee5f325332ff92a03af539851d0d05f0dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f6d76617373732f6c61726176656c2d75726c2d616c69617365732e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/fomvasss/laravel-url-aliases)[![Quality Score](https://camo.githubusercontent.com/0b520f0fa2e3a81aeb6211c22e68de884d14dfb474f968dea1716da850372384/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f666f6d76617373732f6c61726176656c2d75726c2d616c69617365732e7376673f7374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/fomvasss/laravel-url-aliases)

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

[](#installation)

1. Require this package with composer

```
composer require fomvasss/laravel-url-aliases
```

2. Publish package resource:

```
php artisan vendor:publish --provider="Fomvasss\UrlAliases\ServiceProvider"
```

- config
- migration

3. Run migrate:

```
php artisan migrate
```

Integration
-----------

[](#integration)

1. Add to your model next trait: `Fomvasss\UrlAliases\Traits\UrlAliasable`

This trait have next relation-method:

- `urlAlias()` - related UrlAlias model

> Do not forget use `with('urlAlias')` in your models when you get list!

2. Add the middleware to `Http/Kernel.php`:

```
    protected $middleware = [
        //...
        \Fomvasss\UrlAliases\Middleware\UrlAliasMiddleware::class,
    ];
```

Usage
-----

[](#usage)

### Facade

[](#facade)

- `\Fomvasss\UrlAliases\Facades\UrlAlias::route('article.show', $article)`
- `\Fomvasss\UrlAliases\Facades\UrlAlias::current()`

### Helper functions

[](#helper-functions)

- `route_alias()` - works the same way as Laravel helper `route()`
- `url_alias_current()` - return alias path (or system path if alias not exists)
- `prepare_url_path()` - return path for URL:  -&gt; my-first-page/example

### Examples usage

[](#examples-usage)

- `routes/web.php`:

```
Route::group(['namespace' => 'Front'], function () {
    //...
    Route::get('article', 'ArticleController@index')->name('article.index');
    Route::get('article/{id}', 'ArticleController@show')->name('article.show');
    Route::post('article', 'ArticleController@store')->name('article.store');
	//...
});
```

- `app/Http/Controllers/Front/ArticleController.php`:

```
public function index(Request $request)
{
    $articles = \App\Models\Article::paginate($request->per_page);

    // foreach($articles as $article) {
    //	 dump(route_alias('article.show', $article));
    // }

    return view('article.index', compact('articles'));
}

public function store(Request $request)
{
    $article = \App\Models\Article::create($request->only([
        //...
    ]);

    // 1) Make alias for system route:
    $article->urlAlias()->create([
        'source' => trim(route('article.show', $article, false), '/'),      // Ex.: system/article/26
        'alias' => str_slug($article->title).'/'.str_slug($article->user->name), // must be unique! Ex.: my-first-article/taylor-otwell
    ]);

    // 2) Or custom redirection:
    $article->urlAlias()->create([
        'source' => 'about',
        'alias' => 'page/about'
        'type' => 301, // Status Code
    ]);

	// 3) Or if external link:
	$article->urlAlias()->create([
		'source' => 'https://google.com.ua',
		'alias' => 'my-google'
		'type' => 302, // Status Code
	]);

    return redirect()->route('article.index');
}

public function show(Request $request, $id)
{
    $article = \App\Models\Article::findOrFail($id);

    // dump($article->urlAlias);
    // dump($article->urlA());

    return view('article.show', compact('article'));
}
```

```
System Link - 301 redirect to alias (if exists)
System path - redirect to alias (if exists)
All articles
Alias Link to article - absolute path
Alias Link to article - relative path
System Link - if not exist alias
Alias Link to article - absolute path
Current path (alias or system)
```

> In `UrlAlias::current()` (`route_alias()`) second argument (if array - first index) may be `id` or the instanceof `\Illuminate\Database\Eloquent\Model` (like `route` Laravel helper)

---

Use localization URL's (dev)
----------------------------

[](#use-localization-urls-dev)

For use localization url's, you need do next steps:

1. Add to `Http/Kernel.php` next middleware:

```
    protected $routeMiddleware = [
        //...
        'applyUrlLocaleToRootPage' => \Fomvasss\UrlAliases\Middleware\ApplyUrlLocaleToRootPage::class,
    ];
```

2. Set in `config/url-aliases.php`: 'use\_localization' =&gt; true,
3. Uncomment needed locales in `config/url-aliases-laravellocalization.php` and set other params
4. Make or change your home page (root) routes, for example:

```
Route::get('/{locale?}', function () {
    return view('home');
})->name('home')->middleware('applyUrlLocaleToRootPage');
```

5. Save aliases for entity and set locale:

```
    $article->urlAlias()->create([
        'source' => trim(route('system.article.show', $article, false), '/'),		// Ex.: system/article/26
        'alias' => str_slug($article->title).'/'.str_slug($article->user->name),	// Must be unique! Ex.: my-first-article/taylor-otwell
        'locale' => 'en',
        'locale_bound' => 123,                                                      // for related locale aliases
    ]);
```

6. Use facade `UrlAliasLocalization` and next methods (like in [mcamara/laravel-localization](https://github.com/mcamara/laravel-localization)):

```
    UrlAliasLocalization::getDefaultLocale()
    UrlAliasLocalization::getCurrentLocale()
    UrlAliasLocalization::getCurrentLocaleName()
    UrlAliasLocalization::getCurrentLocaleNative()
    UrlAliasLocalization::getCurrentLocaleNativeReading()
    UrlAliasLocalization::getCurrentLocaleRegional()
    UrlAliasLocalization::getCurrentLocaleDirection()
    UrlAliasLocalization::getCurrentLocaleScript()
    UrlAliasLocalization::getLocalesOrder()
    UrlAliasLocalization::getSupportedLocales()
    UrlAliasLocalization::getSupportedLanguagesKeys()
    UrlAliasLocalization::getRoot() // http://site.com/ua, http://site.com/de
    UrlAliasLocalization::getCurrentBound() // Get locales and links to related locale aliases
    UrlAliasLocalization::getLocaleModelBound()
    UrlAliasLocalization::getLocalesModelsBound()
```

Links
-----

[](#links)

-

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 94.7% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/91ed81cc24fd4f926c0aec81c9034bb08bd55ddf590ee5dd58a4d6db5a6e1175?d=identicon)[creutz](/maintainers/creutz)

---

Top Contributors

[![fomvasss](https://avatars.githubusercontent.com/u/19834478?v=4)](https://github.com/fomvasss "fomvasss (36 commits)")[![meccaneuemedien](https://avatars.githubusercontent.com/u/48958196?v=4)](https://github.com/meccaneuemedien "meccaneuemedien (2 commits)")

### Embed Badge

![Health badge](/badges/creutz-laravel-url-aliases/health.svg)

```
[![Health](https://phpackages.com/badges/creutz-laravel-url-aliases/health.svg)](https://phpackages.com/packages/creutz-laravel-url-aliases)
```

###  Alternatives

[components/jqueryui

jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications or you just need to add a date picker to a form control, jQuery UI is the perfect choice.

1795.8M57](/packages/components-jqueryui)[clue/graph-composer

Dependency graph visualization for composer.json

93798.0k11](/packages/clue-graph-composer)[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)

PHPackages © 2026

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