PHP code example of sujan97825 / laravel-slug-generator

1. Go to this page and download the library: Download sujan97825/laravel-slug-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sujan97825 / laravel-slug-generator example snippets


'providers' => [
    // ...
    Sujan\\LaravelSlugGenerator\\SlugGeneratorServiceProvider::class,
    // ...
],

'aliases' => Facade::defaultAliases()->merge([
    // ...
    'SlugGenerator' => Sujan\LaravelSlugGenerator\Facades\SlugGenerator::class,
    // ...
])->toArray(),

use Sujan\LaravelSlugGenerator\Facades\SlugGenerator;

use App\Models\Post;

// First time create post with title
SlugGenerator::uniqueSlug(Post::class, 'সম্পন্ন !#$%$%^ হল বঙ্গবন্ধু&**( টানেলের //? প্রথম টিউবের )()(**@%$^&*( কাজ  ', 'slug');
// Output: সম্পন্ন-হল-বঙ্গবন্ধু-টানেলের-প্রথম-টিউবের-কাজ

// Second time create post with title
SlugGenerator::uniqueSlug(Post::class, 'সম্পন্ন !#$%$%^ হল বঙ্গবন্ধু&**( টানেলের //? প্রথম টিউবের )()(**@%$^&*( কাজ  ', 'slug');
// Output: সম্পন্ন-হল-বঙ্গবন্ধু-টানেলের-প্রথম-টিউবের-কাজ-1

// Third time create post with title
SlugGenerator::uniqueSlug(Post::class, 'সম্পন্ন !#$%$%^ হল বঙ্গবন্ধু&**( টানেলের //? প্রথম টিউবের )()(**@%$^&*( কাজ  ', 'slug');
// Output: সম্পন্ন-হল-বঙ্গবন্ধু-টানেলের-প্রথম-টিউবের-কাজ-2

// First time create post with title
SlugGenerator::generalSlug('সম্পন্ন !#$%$%^ হল বঙ্গবন্ধু&**( টানেলের //? প্রথম টিউবের )()(**@%$^&*( কাজ  ');
// Output: সম্পন্ন-হল-বঙ্গবন্ধু-টানেলের-প্রথম-টিউবের-কাজ

// Second time create post with title
SlugGenerator::generalSlug('সম্পন্ন !#$%$%^ হল বঙ্গবন্ধু&**( টানেলের //? প্রথম টিউবের )()(**@%$^&*( কাজ  ');
// Output: সম্পন্ন-হল-বঙ্গবন্ধু-টানেলের-প্রথম-টিউবের-কাজ


SlugGenerator::uniqueSlug($model, $value, $field, $separator);
SlugGenerator::generalSlug($value,$separator);

/**
 * Generate a Unique Slug.
 *
 * @param object $model
 * @param string $value
 * @param string $field
 * @param string $separator
 *
 * @return string
 * @throws \Exception
 */
public function uniqueSlug(
    $model,
    $value,
    $field,
    $separator = null
): string

/**
 * Generate a general Slug.
 *
 * @param string $value
 * @param string $separator
 *
 * @return string
 */
public function generalSlug(
    $value,
    $separator = null
): string


return [
    /*
    |--------------------------------------------------------------------------
    | Slug default separator.
    |--------------------------------------------------------------------------
    |
    | If no separator is passed, then this default separator will be used as slug.
    |
    */
    'separator' => '-',

    /*
    |--------------------------------------------------------------------------
    | Slug max count limit
    |--------------------------------------------------------------------------
    |
    | Default 100, slug will generated like
    | test-1, test-2, test-3 .... test-100
    |
    */
    'max_count' => 100,
];



https://github.com/ManiruzzamanAkash/laravel-unique-slug-generator

sh
php artisan vendor:publish --provider="Sujan\LaravelSlugGenerator\SlugGeneratorServiceProvider"