PHP code example of josezenem / laravel-slugidable

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

    

josezenem / laravel-slugidable example snippets


$model = new Blog();
$model->title = 'Dwight jumped over the fence';
$model->save();

echo $model->slug; // output: dwight-jumped-over-the-fence-012422

// App\Models\Blog


use Josezenem\Slugidable\Slugidable;

class Blog extends Model {
    use Slugidable;
    
    protected $fillable = [
        'title',
        'slug',
    ];
}

$blog = create([
    'title' => 'My dog Dwight jumped over the fence',
])

// When this is created, it will make the slug of
//my-dog-dwight-jumped-over-the-fence-1

$blog = Blog::fromSlugidable('my-dog-dwight-012422')->first();

// in this scenario only ID: 012422 is used inside the scope to find the slug.


protected function configureSlugidableSettings():void
{
    $this->slugidableSettings = [
        'slug_from' => 'title',
        'slug_to' => 'slug',
        'using_key_name' => $this->getKeyName(),
        'on' => 'suffix',
        'using_separator' => '-',
        'force_slug_from' => false,
    ];
}