PHP code example of coding-wisely / laravel-slug-auto-generator

1. Go to this page and download the library: Download coding-wisely/laravel-slug-auto-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/ */

    

coding-wisely / laravel-slug-auto-generator example snippets


// config for CodingWisely/SlugGenerator
// replace it with your model column
return [
    'sluggable_field' => 'name',
    'groupable_field' => null, // 'category_id',
];


use CodingWisely\SlugGenerator\SlugGenerator;
use Illuminate\Database\Eloquent\Model;

class YourModel extends Model
{
    use SlugGenerator;

    // Your model's attributes and methods...
    
    // override config file with 
    public static function getSluggableField(): string
    {
        return 'title'; // your own field on Model
    }
    // if you want to have unique slugs in different categories (groupable, such as project_id, team_id, category_id, etc.)
    public static function getGroupableField(): ?string
    {
        return 'category_id'; // your own field on Model
    }
}