PHPackages                             dewan/dewan-multilang-slug - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dewan/dewan-multilang-slug

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dewan/dewan-multilang-slug
==========================

It takes a string, a model, a filed, and a divider, and returns a unique string with a number or random string appended to it if the slug already exists in the database.

v3.0.2(1y ago)0329MITPHPPHP &gt;=7.4

Since Aug 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/shamimdewan390/dewan-multilang-slug-generator)[ Packagist](https://packagist.org/packages/dewan/dewan-multilang-slug)[ Docs](https://github.com/shamimdewan390/dewan-multilang-slug-generator)[ RSS](/packages/dewan-dewan-multilang-slug/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependenciesVersions (9)Used By (0)

dewan-multilang-slug-generator
==============================

[](#dewan-multilang-slug-generator)

here is doc

Installation
------------

[](#installation)

> Run this command for install package.

```
composer require dewan/dewan-multilang-slug
```

> Run this command for config publish.

```
php artisan vendor:publish --tag=dewan-multilang-slug-config --force
```

Basic use
---------

[](#basic-use)

### Example #01- Post unique slug from title

[](#example-01--post-unique-slug-from-title)

Let's assume, we have in `Team` class, Now, if we passed `title` and generate `slug` from that it will generated unique slug depend on slug field, then -

```
use App\Models\Team;

// First time create post with title Simple Post
MultilangSlug::makeSlug(Team::class, 'Team title');
// Output: team-title

// Second time create post with title Simple Post
MultilangSlug::makeSlug(Team::class, 'Team title');
// Output: team-title-1

// Third time create post with title Simple Post
MultilangSlug::makeSlug(Team::class, 'Team title');
// Output: team-title-2
```

If we pass 3rd parameter and if we passed `title` and generate `slug` from that it will generated unique slug depend on team\_slug field, then -

```
use App\Models\Team;

// First time create post with title Simple Post
MultilangSlug::makeSlug(Team::class, 'Team title', 'team_slug');
// Output: team-title

// Second time create post with title Simple Post
MultilangSlug::makeSlug(Team::class, 'Team title', 'team_slug');
// Output: team-title-1

// Third time create post with title Simple Post
MultilangSlug::makeSlug(Team::class, 'Team title', 'team_slug');
// Output: team-title-2
```

### Example-1 - Unique slug for Team or any model easily

[](#example-1---unique-slug-for-team-or-any-model-easily)

```
public function store(array $data): Team|null
{
    $title = "here is title";
    $data = Team::create([
        "title" => $title,
        'slug' => MultilangSlug::makeSlug(Team::class, $title),
    ]);
    return $data;
}
```

### Example-2 - Unique slug for Post or any model easily

[](#example-2---unique-slug-for-post-or-any-model-easily)

```
public function create(array $data): Post|null
{
    if (empty($data['slug'])) {
        $data['slug'] = MultilangSlug::makeSlug(Post::class, $data['name']);
    }

    return Post::create($data);
}
```

API Docs
--------

[](#api-docs)

### Generate method -

[](#generate-method--)

```
MultilangSlug::makeSlug($model, $slugText, $field, $divider);
```

```
/**
 * Generate a Unique Slug.
 *
 * @param object $model
 * @param string $slugText
 * @param string $field
 * @param string $divider
 *
 * @return string
 * @throws \Exception
 */
public function makeSlug(
    $model,
    $slugText,
    $field,
    $divider = null
): string
```

#### Configurations

[](#configurations)

```
