Search by

kiran99 / laravel-slug-generator

Kiran151

This is my package laravel-slug-generator

Package info

github.com/Kiran151/laravel-slug-generator

pkg:composer/kiran99/laravel-slug-generator

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-09-07 12:06 UTC

This package is auto-updated.

Last update: 2026-09-08 12:01:02 UTC


README

A simple Laravel package for generating URL-friendly slugs.

Installation

You can install the package via Composer:

composer require kiran99/laravel-slug-generator

The package is automatically registered through Laravel package auto-discovery.

Usage

You can generate a slug using the Slug facade:

use kiran99\LaravelSlugGenerator\Facades\Slug;

$slug = Slug::make('Hello Laravel Package');

echo $slug;

Output:

hello-laravel-package

Configuration

The package uses a configuration file:

config/slug.php

The default configuration is:

return [
    'separator' => '-',
];

You can publish the configuration file to your Laravel application:

php artisan vendor:publish --tag=slug-config

After publishing, you can change the separator:

return [
    'separator' => '_',
];

Then:

Slug::make('Hello Laravel Package');

will return:

hello_laravel_package

Dependency Injection

The package provides a SlugGeneratorInterface contract:

use kiran99\LaravelSlugGenerator\Contracts\SlugGeneratorInterface;

The package binds the interface to SlugService through the Laravel service container.

You can inject the interface into your own classes:

use kiran99\LaravelSlugGenerator\Contracts\SlugGeneratorInterface;

class ArticleService
{
    public function __construct(
        protected SlugGeneratorInterface $slugGenerator
    ) {
    }

    public function generateSlug(string $title): string
    {
        return $this->slugGenerator->make($title);
    }
}

Laravel automatically resolves SlugService when SlugGeneratorInterface is requested.

Facade

For simple usage, you can use the facade:

use kiran99\LaravelSlugGenerator\Facades\Slug;

Slug::make('Hello World');

The facade resolves the package service through Laravel's service container.

Testing

Run the package tests with:

composer test

License

This package is open-sourced software licensed under the MIT license.