https://github.com/tomhatzer/nova-slug-field
Slug field for Laravel Nova
https://github.com/tomhatzer/nova-slug-field
laravel laravel-nova nova slug
Last synced: 5 months ago
JSON representation
Slug field for Laravel Nova
- Host: GitHub
- URL: https://github.com/tomhatzer/nova-slug-field
- Owner: tomhatzer
- License: mit
- Created: 2018-08-25T10:55:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-27T12:11:49.000Z (over 2 years ago)
- Last Synced: 2025-10-08T06:45:01.879Z (9 months ago)
- Topics: laravel, laravel-nova, nova, slug
- Language: Vue
- Size: 276 KB
- Stars: 143
- Watchers: 4
- Forks: 26
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel Nova Slug Field
Simple Laravel Nova Slug field. Generating a slugified version of a text
input. See the result of the slug while typing.
### Edit form

## Installation
In order to use this package, you need a Laravel installation which uses [Nova](https://nova.laravel.com).
**Composer**
```bash
composer require benjaminhirsch/nova-slug-field
```
## Usage
Define the following fields in your resource in the ```fields``` method:
```
use Benjaminhirsch\NovaSlugField\Slug;
use Benjaminhirsch\NovaSlugField\TextWithSlug;
...
TextWithSlug::make('Name')
->slug('slug'),
Slug::make('Slug'),
```
##### Slug with a preview of the generated URL
This will display the full URL including the generated slug as a link below the input field.
```
use Benjaminhirsch\NovaSlugField\Slug;
use Benjaminhirsch\NovaSlugField\TextWithSlug;
...
TextWithSlug::make('Name')
->slug('slug'),
Slug::make('Slug')
->showUrlPreview('http://www.foo.bar'),
```
##### Slug with disabled auto update
This is especially usefull, when you are updating the field which the slug belongs to and don't wan't the slug to be updated automatically.
```
use Benjaminhirsch\NovaSlugField\Slug;
use Benjaminhirsch\NovaSlugField\TextWithSlug;
...
TextWithSlug::make('Name')
->slug('slug'),
Slug::make('Slug')
->disableAutoUpdateWhenUpdating(),
```
This first field definition is the field which you want to create the slug of. The second field
definition represents the slugified version. With the ```->slug('name')``` method, you define
the name of the field which holds the slug. It is possible to create multiple slugs on a single
resource, just add more field definitions. Every ```TextWithSlug``` field needs a corresponding
```Slug``` field.