PHP code example of namest / sluggable

1. Go to this page and download the library: Download namest/sluggable 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/ */

    

namest / sluggable example snippets


return [
    ...
    'providers' => [
        ...
        'Namest\Sluggable\SluggableServiceProvider',
    ],
    ...
];

class User extends Model
{
    use \Namest\Sluggable\HasSlug;
    
    // ...
}

$post->slug = 'the-new-post';
$post->save(); // Save post & slug;

$slug = $post->slug; // Get slug string

Slug::isValid($name); // Check a name is valid for slug: unique & sluged
Slug::regenerate($name); // Regenerate a slug if its invalid
Slug::regenerate($name, true); // Regenerate a slug without check its valid or not
bash
php artisan vendor:publish --provider="Namest\Sluggable\SluggableServiceProvider"
bash
php artisan migrate