Code Monkey home page Code Monkey logo

nova-slug-field's Introduction

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

details page select

Installation

In order to use this package, you need a Laravel installation which uses Nova.

Composer

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.

nova-slug-field's People

Contributors

benjaminhirsch avatar crynobone avatar cyriljshaz avatar dennislindsey avatar drobee avatar duckzland avatar joonas1234 avatar nick-f avatar tomhatzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nova-slug-field's Issues

Enforce unique slug

Hi Benjamin,

How would I enforce unique slugs for each model? I am using 'cviebrock/eloquent-sluggable' but the unique'ability is not enforced when creating/updating from Nova!

Best regards,
K...

Option To Show Full URL

Hey @benjaminhirsch thanks for the cool field package, short and sweet and well done 👍

I couldn't seem figure out how to submit a feature request type Issue, so sorry in advance if this is in the wrong spot.

I think it would be really useful/cool to add a ->showPreviewUrl($prefix) option (or something similar) that would show a preview of the full URL, ex: https://www.yoursite.com/super-cool-slug/ underneath/to the side of the slug text box.

Anyone else find this useful?

Thanks again for the hard work on the package.

Custom slug function

Would be great to be able to customize the slug function used, in the Nova resource, ideally

Nova 4.0

Hey, any chance to update this package to Nova 4.0?
The issue is the TextWithSlug field does not show up on any screen.

Request: Remove TextWithSlug

Would it be possible to just use Slug and not TextWithSlug

ID::make()->sortable(),
Unique::make('Email'),
Slug::make('Slug')->from('Email'),

exisitng slug shouldn't auto-update

Once a slug has beend saved it shouldn't auto-update as this would break backlinks.
May I suggest it only writes the slug if the slug has value = ''. This way I could manually clear a slug to make it auto generate again*.

*As the slug is a required field, clearing the slug should instantly, automatically polulate it from the TextWithSlug field's value (as it can't be empty).

I also upvote the sugestion for a single field using ->parent('title') or ->from('title') as a more flexible way to get the slug value.

I also upvote the ->unique() sugestion as slugs should be unique. This could be unique to resolve uri rarther than on it's own. ..meaning i could have multiple slugs called 'foobar' if each resolve to a unique URI.

thanks for the field. best of luck with it.

Placeholder not respected

Hi Benjamin,

Thank you for creating this awesome field!

Could you please fix the issue where the placeholder is not respected?

Example below:

TextWithSlug::make('Title')->sortable()->rules('required', 'max:96')->withMeta(['extraAttributes' => [
'placeholder' => 'Magazine',
'maxlength' => 96
]])->slug('Slug')

In this scenario, the output placeholder is "Title", while it should be "Magazine".

Looking forward to the fix!

Set label for Slug field

Hi
this code works:

TextWithSlug::make('Название', 'name')
    ->slug('Slug'),
Slug::make('Slug'),

but this not works:

TextWithSlug::make('Название', 'name')
    ->slug('slug'),
    // or 
    // ->slug('Slug'),
Slug::make('Ярлык', 'slug'),

how to set label 'Ярлык' for Slug field ?

disableAutoUpdateWhenUpdating not working

I am on nova v2.8.0 and trying out your package.

When I use the disableAutoUpdateWhenUpdating() method, the slug field isn't updating at all. When I remove it, it is behaving like expected (updating the slug field also on update view)

Feature? Combine 2 fields into 1 slug?

Great work on this field.
It would be nice to have a feature to combine 2 fields into one slug.

We have a table with staff members which have first_name and last_name and would like to create a slug from the 2 fields combined.

e.g. first_name: Paul, last_name: Lawton - results in a slug of paul-lawton
(The fields are separate so that we can sort alphabetically on the surname)

Slug not updating while typing after updating to v1.2.1

Hello, possible bug report here.

I just updated nova-slug-field to v1.2.1 and my slug field has stopped updating when typing into the source field. This occurs when creating a new record or updating an existing record. I'm not seeing any errors in the console and downgrading to v1.1.1 resolves the issue. Perhaps I'm doing something wrong or the configuration has changed with the new version.

Here's the relevant fields from my Nova resource:

TextWithSlug::make('Name')
    ->slug('Slug')
    ->rules('required')
    ->sortable(),

Slug::make('Slug')
    ->rules('required', 'alpha_dash')
    ->creationRules('unique:properties,slug')
    ->updateRules('unique:properties,slug,{{resourceId}}')
    ->sortable()
    ->hideFromIndex(),

My project is on Laravel 5.8.14 with all dependencies updated:

"require": {
  "php": "^7.2",
  "benjaminhirsch/nova-slug-field": "^1.1",
  "fideloper/proxy": "^4.0",
  "gregoriohc/laravel-nova-theme-responsive": "^0.6.1",
  "intervention/image": "^2.4",
  "laravel/framework": "^5.8",
  "laravel/nova": "^2.0",
  "laravel/telescope": "^2.0",
  "laravel/tinker": "^1.0"
},
"require-dev": {
  "beyondcode/laravel-dump-server": "^1.0",
  "filp/whoops": "^2.0",
  "fzaninotto/faker": "^1.4",
  "mockery/mockery": "^1.0",
  "nunomaduro/collision": "^3.0",
  "phpunit/phpunit": "^8.0"
},

@benjaminhirsch Thanks for looking into this, and for nova-slug-field. Its super useful and should be merged into Nova if you ask me!

Render a help text the field

Nova fields have help text that can be specified by ->help($text) method. Both TextWithSlug and Slug don’t render this help text.

Looking for a new maintainer!

Due to the fact that I no longer activley working with Laravel as a Framework, I'm looking for someone who is willing to maintain this little project in the future. If you're interested, let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.