Skip to content

rajibbinalam/laravel-unique-slug-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laravel-unique-slug-generator

composer require rajibbinalam/laravel-slug-generator

update config/app.php

"providers": [
    Rajib\LaravelSlugGenerator\SlugGeneratorServiceProvider::class,
],

"aliases": {
    'SlugGenerator' => Rajib\LaravelSlugGenerator\Facades\SlugGenerator::class,
}

Publish Vendor:

php artisan vendor:publish

Generating a unique slug

use Rajib\LaravelSlugGenerator\Facades\SlugGenerator;

//SlugGenerator::generate($model, '$title', '$db_field_name');
SlugGenerator::generate(User::class, 'Hello World', 'slug');

Separating a slug with '-'. Default Separated with '-'. It's changable. In config/SlugGenerator

'separator' => '-',

Also we can change the number of slugs make from same title. config/SlugGenerator

'max_count' => '100',

Example: Make Multiple slug from Same Title

SlugGenerator::generate(User::class, 'Hello World', 'slug');  // output: hello-world

SlugGenerator::generate(User::class, 'Hello World', 'slug');  // output: hello-world-1

SlugGenerator::generate(User::class, 'Hello World', 'slug');  // output: hello-world-2

SlugGenerator::generate(User::class, 'Hello World', 'slug');  // output: hello-world-3