PHPackages                             rjvandoesburg/laravel-nova-url-rewrite-templating - 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. [Templating &amp; Views](/categories/templating)
4. /
5. rjvandoesburg/laravel-nova-url-rewrite-templating

ActiveLibrary[Templating &amp; Views](/categories/templating)

rjvandoesburg/laravel-nova-url-rewrite-templating
=================================================

A package that combines the power of Laravel Nova Templating and Laravel Nova Url Rewrites

1.0.0(6y ago)02MITPHPPHP ^7.2CI failing

Since Nov 19Pushed 6y ago1 watchersCompare

[ Source](https://github.com/rjvandoesburg/laravel-nova-url-rewrite-templating)[ Packagist](https://packagist.org/packages/rjvandoesburg/laravel-nova-url-rewrite-templating)[ RSS](/packages/rjvandoesburg-laravel-nova-url-rewrite-templating/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (4)Versions (2)Used By (0)

Combining URL rewrites with dynamic JS templating for your Laravel Nova powered application
===========================================================================================

[](#combining-url-rewrites-with-dynamic-js-templating-for-your-laravel-nova-powered-application)

This packages is build on top of two other packages:

- [Laravel Nova templating](https://github.com/rjvandoesburg/laravel-nova-templating): Add dynamic JS template loading to your Laravel Nova powered application
- [Laravel Nova Url Rewrite](https://github.com/rjvandoesburg/laravel-nova-url-rewrite): Add Url Rewrites to your Laravel Nova powered application

I was building a Laravel Nova application but was missing the front-end ease-of-use in combination with Nova. [Ruthger Idema](https://github.com/ruthgeridema) had built a url rewrite package which he was using with Nova, but was using Laravel for the routing. I was also using Nova but was using Vue.js for my front-end so I wanted pretty urls and to just build my front-end via an API.

Because people might want just one or the other I made 3 packages (templating, url rewrite and one that combines the other two)

What this package allows you to do is use Nova for your resources, add url rewrites so urls are nice and pretty and call an endpoint from your JS application and you will receive a list of potential templates to load.

Requirements
------------

[](#requirements)

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

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

[](#installation)

You can install the package via composer:

```
composer require rjvandoesburg/laravel-nova-url-rewrite-templating
```

The package will automatically register itself.

### Routing

[](#routing)

Instead of using the route provided in [Laravel Nova templating](https://github.com/rjvandoesburg/laravel-nova-templating) you need to add the following to your routes file (preferably `api.php`)

```
Route::NovaUrlRewriteTemplates();
```

Which will add the following routes:

- `/template-api/{resource}/{resourceId}`
- `/template-api/{templateUrl?}`

If the resource route returns a 404 it will try the other url as well.

[Laravel Nova Url Rewrite](https://github.com/rjvandoesburg/laravel-nova-url-rewrite#publish) comes with a migration, config and translations, please have a look if you wish to publish any of these files.

Usage
-----

[](#usage)

Much like the usage of [Laravel Nova templating](https://github.com/rjvandoesburg/laravel-nova-templating#usage) new endpoints will be available and return a list of names you can use for templating. However a 'cach-all' route is added with this package which will look for a url rewrite to decide what to return.

A typical response could be:

```
{
  "templates": [
    "user-1",
    "user",
    "model",
    "index"
  ]
}
```

However if it is just a route without a resource and or model, the response is quite small:

```
{
  "templates": [
    "home",
    "index"
  ]
}
```

(This needs work, e.g. a name could be generated based on the Request path and Target path)

In this case I would advise using a `Page` resource which will allow you to define the look and feel for a page.

### Redirects

[](#redirects)

When a url rewrite is a redirect the response is a little bit different as no templates are returned:

```
{
    "redirect": "/users/1",
    "status": 302,
    "isExternal": false
}
```

The redirect path is returned as with the status (allthough chances are you cannot return a server response) and if the redirect is to an external url.

### VueJs

[](#vuejs)

Say you want to use this within Vue, here is an example of how you could implement this:

```
const files = require.context('./templates/', true, /\.vue$/i);
files.keys().map(key => Vue.component('template-'+key.split('/').pop().split('.')[0], files(key).default));
```

From `app.js` I am loading all files within the `templates` folder and prefixing `template` as the name when registring them with Vue.

- `templates/index.vue` will be registered as `template-index`
- `templates/user.vue` will be registered as `template-user`
- `templates/user-1.vue` will be registered as `template-user-1`

Create a Vue file that will be rendered on specific routes. In the example I am using `vue-router` and `beforeRouteEnter` to retrieve the correct template based on the current url.

```

    export default {
        beforeRouteEnter(to, from, next) {
            return axios.get(`/template-api${path}`)
                .then(({data: response}) => {
                    if (response.redirect !== undefined) {
                        if (response.isExternal) {
                            window.location = response.redirect
                            return
                        }
                        this.$router.push(response.redirect)
                        return;
                    }

                    this.route = response
                })
                .then(next)
                .catch(error => {
                    // Show an error or redirect to an error page, dealer's choice
                })
        },

        data: () => ({
            template: null,
            route: null,
        }),

        created() {
            _.forEach(this.route.templates, template => {
                if (Vue.options.components[`template-${template}`] !== undefined) {
                    this.template = template
                    return false
                }
            })
        },
    }

```

TODO
----

[](#todo)

- Better templating for non resource/model routes

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Robert-John van Doesburg](https://github.com/rjvandoesburg)
- [All Contributors](../../contributors)

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

- [Spatie](https://spatie.be)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2366d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef542e46d16089dac6cd4c5256088f4f66aa39255fd7795aee3848b88b57f546?d=identicon)[rjvandoesburg](/maintainers/rjvandoesburg)

### Embed Badge

![Health badge](/badges/rjvandoesburg-laravel-nova-url-rewrite-templating/health.svg)

```
[![Health](https://phpackages.com/badges/rjvandoesburg-laravel-nova-url-rewrite-templating/health.svg)](https://phpackages.com/packages/rjvandoesburg-laravel-nova-url-rewrite-templating)
```

###  Alternatives

[cagilo/cagilo

A set of open-source Blade components for the Laravel Framework

172996.5k](/packages/cagilo-cagilo)[orchid/blade-icons

An easy way inline SVG images in your Blade templates.

223.4M9](/packages/orchid-blade-icons)[wireui/heroicons

The Tailwind Heroicons for laravel blade by WireUI

43390.8k5](/packages/wireui-heroicons)[stillat/antlers-components

2656.0k1](/packages/stillat-antlers-components)[itstructure/laravel-grid-view

Grid view for laravel framework

2546.6k2](/packages/itstructure-laravel-grid-view)[ycs77/inertia-laravel-ssr-head

Simple SSR Head for Inertia Laravel

3211.5k](/packages/ycs77-inertia-laravel-ssr-head)

PHPackages © 2026

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