PHP code example of irfanchowdhury / unique-slug-generate
1. Go to this page and download the library: Download irfanchowdhury/unique-slug-generate 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/ */
irfanchowdhury / unique-slug-generate example snippets
use App\Models\Post;
// First time create post with title Simple Post
UniqueSlug::generate(Post::class, 'Simple Post', 'slug');
// Output: simple-post
// Second time create post with title Simple Post
UniqueSlug::generate(Post::class, 'Simple Post', 'slug');
// Output: simple-post-1
// Third time create post with title Simple Post
UniqueSlug::generate(Post::class, 'Simple Post', 'slug');
// Output: simple-post-2
// First time create user.
UniqueSlug::generate(User::class, 'akash', 'username', ''); // akash
// Second time create user.
UniqueSlug::generate(User::class, 'akash', 'username', ''); // akash1
// Third time create user.
UniqueSlug::generate(User::class, 'akash', 'username', ''); // akash2
public function create(array $data): Category|null
{
if (empty($data['slug'])) {
$data['slug'] = UniqueSlug::generate(Category::class, $data['name'], 'slug');
}
return Category::create($data);
}
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,
];
sh
php artisan vendor:publish akash/laravel-unique-slug
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.