Laravel URL Rewrites is a good package that we can use to add URL rewrites to a Laravel app easily.

laravel url rewrites

Installation

You can install the package via composer:

composer require ruthgeridema/laravel-url-rewrites

The package will automatically register itself.

Register the routes the feeds will be displayed on using the rewrites-macro. You need to place it at the bottom of your routes file.

// In routes/web.php
Route::rewrites();

You can publish the migration with:

php artisan vendor:publish --provider="RuthgerIdema\UrlRewrite\ServiceProvider" --tag="migrations"

After the migration has been published you can create the url_rewrites table by running the migration:

php artisan migrate You can optionally publish the config file with:

php artisan vendor:publish --provider="RuthgerIdema\UrlRewrite\ServiceProvider" --tag="config"

This is the contents of the published config file:

<?php

return [
    'table-name' => 'url_rewrites',
    'repository' => \RuthgerIdema\UrlRewrite\Repositories\UrlRewriteRepository::class,
    'model' => \RuthgerIdema\UrlRewrite\Entities\UrlRewrite::class,
    'cache' => true,
    'cache-decorator' => \RuthgerIdema\UrlRewrite\Repositories\Decorators\CachingUrlRewriteRepository::class,
    'types' => [
        'product' => [
            'route' => 'product',
            'attributes' => ['id'],
        ],
        'category' => [
            'route' => 'category',
            'attributes' => ['id'],
        ]
    ],
];

Source Code

https://github.com/ruthgeridema/laravel-url-rewrites