Search by

aakashk-ctpl / laravel-slug

aakashk-ctpl

Generate clean, URL-friendly slugs from text in Laravel applications.

Package info

github.com/aakashk-ctpl/laravel-slug

pkg:composer/aakashk-ctpl/laravel-slug

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-09-25 10:42 UTC

This package is auto-updated.

Last update: 2026-09-25 10:43:05 UTC


README

A small, dependency-light package for generating clean, URL-friendly slugs from text in Laravel applications.

Slug::make('Online Exam Portal');
// online-exam-portal

Slug::make('Laravel Package Development', '_');
// laravel_package_development

Requirements

  • PHP 8.2+
  • Laravel 12 or 13

Installation

This package is not yet published on Packagist. Once it is, you'll be able to install it with:

composer require aakashk-ctpl/laravel-slug

Until then, you can require it locally as a path repository. Add this to your application's composer.json:

{
    "repositories": [
        {
            "type": "path",
            "url": "packages/aakashk-ctpl/laravel-slug"
        }
    ]
}

then run:

composer require aakashk-ctpl/laravel-slug:@dev

The package's service provider and Slug facade are registered automatically via Laravel's package auto-discovery — no manual setup required.

Basic usage

Use the Slug facade:

use Ctpl\LaravelSlug\Facades\Slug;

Slug::make('Online Exam Portal');
// online-exam-portal

Slug::make('Laravel Package Development');
// laravel-package-development

Or resolve the underlying service from the container directly:

use Ctpl\LaravelSlug\SlugGenerator;

app(SlugGenerator::class)->make('Online Exam Portal');
// online-exam-portal

What it handles

  • Lowercases the text
  • Replaces spaces and other whitespace with the separator
  • Removes/replaces unwanted special characters
  • Collapses duplicate separators
  • Trims separators from the start and end
  • Transliterates common Unicode characters to their closest ASCII equivalent (e.g. Café → cafe)

Custom separator

Pass a separator as the second argument to override the default for a single call:

Slug::make('Laravel Package Development', '_');
// laravel_package_development

Configuration

Publish the config file with the slug-config tag:

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

This creates config/slug.php:

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

Change default_separator to set the separator used whenever Slug::make() is called without an explicit one.

Testing

Run the test suite with:

composer test

or directly with PHPUnit:

vendor/bin/phpunit

License

The MIT License (MIT). See LICENSE for more information.