PHP code example of rjvandoesburg / laravel-nova-url-rewrite

1. Go to this page and download the library: Download rjvandoesburg/laravel-nova-url-rewrite library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rjvandoesburg / laravel-nova-url-rewrite example snippets


Route::NovaUrlRewrite()



return [
    'models' => [
        'url_rewrite' => \Rjvandoesburg\NovaUrlRewrite\Models\UrlRewrite::class,
    ],

    'tables' => [
        'url_rewrites' => 'url_rewrites'
    ]
];


/**
 * Get the tools that should be listed in the Nova sidebar.
 *
 * @return array
 */
public function tools()
{
    return [
        \Rjvandoesburg\NovaUrlRewrite\NovaUrlRewriteTool::make(),
    ];
}

    return [
        (\Rjvandoesburg\NovaUrlRewrite\NovaUrlRewriteTool::make())
            ->setUrlRewriteResource(\Rjvandoesburg\NovaUrlRewrite\Nova\UrlRewrite::class),
    ];

$repository = app(\Rjvandoesburg\NovaUrlRewrite\Contracts\UrlRewriteRepository::class);

$builder = $repository->getRewriteBuilder();

$builder->requestPath('/apple-airpods')
        ->targetPath('/products/5');

$urlRewrite = $repository->create($builder);

$product = \App\Models\Product::find(5);

$builder->requestPath('/apple-airpods')
        ->unique()
        ->model($product);

// Because no target_path was provided the builder will look at the provided model/resource and generates a url based on their names.
$urlRewrite = $repository->create($builder);

$product = \App\Models\Product::find(5);
$resource = new \App\Nova\Product($product);

$builder->requestPath('/apple-airpods')
        ->group(0) // Defaults to 0
        ->resource($resource)
        ->unique()
        ->redirectType(\Rjvandoesburg\NovaUrlRewrite\Models\UrlRewrite::FORWARD)
        ->model($product) // This is redundant as the model is bound to the resource
        ->description('Landing page for the NEW apple airpods');

$urlRewrite = $repository->create($builder);
bash
php artisan nova-url-rewrite:regenerate {id?} --group=[default: 0]