Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Sluggable Laravel Package

oleaass/laravel-sluggable

View on GitHub
Deep Wiki
Context7

Add slugs to Eloquent models in Laravel

This package allows you to automatically create and/or update slugs when saving Eloquent models.

Installation

$ composer require oleaass/laravel-sluggable

Usage

Make your Eloquent model sluggable

namespace App\Models;

use OleAass\Sluggable\Sluggable;

class Post extends Model
{
    use Sluggable;
    
    public function getSlugOptions() : array
    {
        return [
            'source' => 'title'
        ];
    }
}

Example

$post = \App\Models\Post::create([
    'title' => 'My first post'
]);

echo $post->slug; // Output: my-first-post

Options

These are the available options, with default values, which you can override via getSlugOptions() on your Eloquent model.

[
    'source'            => 'title', // The field used as source for the slug
    'dest'              => 'slug',  // Name of the slug column
    'onCreate'          => true,    // If true, automatically create slug when creating a new resource
    'onUpdate'          => false,   // If true, automatically change slug when updating an existing resource
    'allowOverwrite'    => true,    // If true, overwrite existing slug when updating a resource
    'allowDuplicate'    => false,   // If true, non unique slugs can be created (recommended to be false always)
    'delimiter'         => '-',     // Replace spaces with this
];

Support Me

I spend my free time making packages. So if you want to support me and my work, I would really appreciate if you bough me a coffee.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky