PHP code example of paxha / laravel-sluggable

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

    

paxha / laravel-sluggable example snippets


Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('slug')->unique();
});

class User extends Model
{
    use \Sluggable\Traits\Sluggable;
}

class User extends Model
{
    use \Sluggable\Traits\Sluggable;

    public static function slugFrom()
    {
        return ['name']; // or return ['first_name', 'last_name'];
    }
 
    public static function slugSaveTo()
    {
        return 'slug'; // or return ['user_slug'];
    }
 
    public static function separator()
    {
        return '-'; // or return '_';
    }
}

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('first_name');
    $table->string('last_name');
    $table->string('slug')->unique();
});

class User extends Model
{
    use \Sluggable\Traits\Sluggable;

    protected $fillable = [
        'first_name', 'last_name',
    ];

    public static function slugFrom()
    {
        return ['first_name', 'last_name'];
    }
}

User::create([
    'first_name' => 'John',
    'last_name' => 'Doe'
]);

// or

$user = new User();
$user->first_name = 'John';
$user->last_name = 'Doe';
$user->save();

Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('user_slug')->unique();
});

class User extends Model
{
    use \Sluggable\Traits\Sluggable;
    
    protected $fillable = [
        'name',
    ];

    public static function slugSaveTo()
    {
        return ['user_slug'];
    }

    public static function separator()
    {
        return '_';
    }
}

User::create([
    'name' => 'John Doe'
]);

// or

$user = new User();
$user->name = 'John Doe';
$user->save();