PHP code example of michaeljmeadows / sluggable

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

    

michaeljmeadows / sluggable example snippets


$table->string('slug')->unique();



namespace App\Models;

use michaeljmeadows\Traits\Sluggable;
use Illuminate\Database\Eloquent\Model;

class NewModel extends Model
{
    use Sluggable;

    protected array $slugFields = [
        'name',
    ];

    public function getRouteKeyName(): string
    {
        return 'slug';
    }	



namespace App\Models;

use michaeljmeadows\Traits\Sluggable;
use Illuminate\Database\Eloquent\Model;

class NewModel extends Model
{
    use Sluggable;
	
    protected string $slugField = 'url_identifier'; // Instead of 'slug'.



namespace App\Models;

use michaeljmeadows\Traits\Sluggable;
use Illuminate\Database\Eloquent\Model;

class NewModel extends Model
{
    use Sluggable;

    protected array $slugFields = [
        'given_name',
        'family_name',
    ];



namespace App\Models;

use michaeljmeadows\Traits\Sluggable;
use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    use Sluggable;
	
    protected array $invalidSlugs = [
        'admin',  
        'create',  
    ];