Download the PHP package rjvandoesburg/laravel-nova-url-rewrite without Composer

On this page you can find all versions of the php package rjvandoesburg/laravel-nova-url-rewrite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-nova-url-rewrite

Add Url Rewrites to your Laravel Nova powered application

Easy to use Url rewrite package. Allowing you to have pretty urls for your Laravel Nova powered application.

Requirements

This package requires Laravel 5.8 or higher, PHP 7.2 or higher.

Installation

You can install the package via composer:

The package will automatically register itself.

RewriteController

Add the following to your routes files to add the RewriteController to your application.

This will register the following route: {request_path} => Rjvandoesburg\NovaUrlRewrite\Http\Controllers\UrlRewriteController with your application. It is recommended to put this as low as possible because it is a catch_all route!

Publish

The package comes with some configuration, translations and with a migration available for publishing.

If you've published the migrations don't forget to run php artisan migrate! Running the migrations will add a table url_rewrites, however the name of this table is configurable in the url_rewrite.php config file.

The contents of the config file are as followed:

At this point only two items are configurable, the table name and the model to use. Should you choose to extend/alter the given model you are free to do so.

Nova resource

To view the url_rewrites in the admin, you need to register the tool in your NovaServiceProvider

It is possible to alter the resource used by using the method setUrlRewriteResource like so:

Of course you need to set it to your own resource.

Usage

The default Url Rewrite has the following fields:

Forward request

Let's say you've registered the following route /product/{id} and you have a product 'Apple Airpods' with an id of 5. When you visit /apple-airpods this package will forward the request to the provided target path but keeps the url clean.

Redirect request

Let's say you used to have a url mac-book-air but the product name has changed so you've added a new url mac-book-rock. To prevent people hitting a 404 page you can add a redirect url rewrite.

Both 301 Moved Permanently and 302 Found (previously described as Moved Temporarily) are available.

When using a redirect request the url will change!

Both an internal url or external url is possible for target path when using the redirect type.

Creating url rewrites via Nova

When using nova for url rewrites you have to provide both the request_path and target_path, the target_path cannot be generated using the Create Url Rewrite page in Nova. (yet)

Creating url rewrites using the builder

This package comes with a 'builder' that allows you to create the Url rewrites on the fly, usually after a model created so it can get the target_path based on the model information.

First you need to DI the repository, either use the constructor or pluck it from the container.

Now that we have an instance of the builder we can construct a url rewrite. Do note that the iterface only requires 2 methods create and regenerate(UrlRewrite $urlRewrite) This is because the repository delegates to the builder when creating or regenerating url rewrites.

The default UrlRewriteBuilder has the following methods available:

Now for some examples.

Adding a simple url rewrite:

Adding a url rewrite based on a model:

And a very extensive one:

Now do note that target_path is not validated if the route 'exists' in your application If this is something you need that you could extend the current builder or add an observer to the UrlRewrite model.

Trait

This package comes with a trait \Rjvandoesburg\NovaUrlRewrite\Models\Traits\UrlRewriteable. You can add the trait to a model that is used with Url Rewrites and it will add a relationship urlRewrites to the model returning a collection of url rewrites.

Regeneration

If you need or want to regenerate one or multiple url rewrites you can do this via Nova actions or via CLI. To rewrite a url the minimum requirement is that the url rewrite has a model, otherwise we would not know what to rewrite to :)

To regenerate the urls via the CLI use the following command.

If no id is specified, all urls will be tried. By default only urls in group 0 are handled. If you wish to regenerate for another group you need to specify that using the group option.

TODO

Contributing

Please see CONTRIBUTING for details.

Credits

Special thanks for Spatie for their guidelines and their packages as an inspiration

I would also like to thank Ruthger Idema for his implementation of Url rewrites

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-nova-url-rewrite with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
laravel/framework Version ~5.8||^6.0
laravel/nova Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rjvandoesburg/laravel-nova-url-rewrite contains the following files

Loading the files please wait ....