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

AbandonedArchivedComposer-package

fomvasss/laravel-url-aliases
============================

Use url-aliases in Laravel project

3.12.0(3y ago)86021MITPHPPHP &gt;=7.1

Since Sep 17Pushed 3y ago3 watchersCompare

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

READMEChangelogDependencies (2)Versions (31)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

33

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity67

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~53 days

Recently: every ~187 days

Total

28

Last Release

1306d ago

Major Versions

0.4.1 → 1.0.02018-10-28

1.0.1 → 2.0.02019-02-11

2.4.1 → 3.0.02019-12-16

PHP version history (4 changes)0.0.1PHP &gt;=7.0.0

3.0.0PHP ^7.2

3.2.0PHP ^7.1.3

3.12.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f99b460639e7d6871597882226b1e0d9e3055992eac8b22bfcd4f90fbdac95c?d=identicon)[fomvasss](/maintainers/fomvasss)

---

Top Contributors

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

---

Tags

urlurilaravelpathalias

### Embed Badge

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

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

###  Alternatives

[league/uri-components

URI components manipulation library

31830.1M52](/packages/league-uri-components)[cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative hashing method.

192560.3k](/packages/cybercog-laravel-optimus)[fsasvari/laravel-trailing-slash

The package that adds redirection with trailing slash to Laravel framework.

61162.4k](/packages/fsasvari-laravel-trailing-slash)[josantonius/url

PHP library to access URL information.

123.2k2](/packages/josantonius-url)

PHPackages © 2026

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