1. Go to this page and download the library: Download ifnicolas/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/ */
ifnicolas / sluggable example snippets
namespace App\Models;
use IfNicolas\Sluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
class Lesson extends Model
{
use Sluggable;
protected $fillable = ['title', 'body'];
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('lessons', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->string('slug')->unique();
$table->text('body');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('lessons');
}
};
return [
/**
* The separator used when generating slugs.
* e.g. 'my title' will be converted to 'my-title'.
*
* Default: '-'.
*/
'separator' => '-',
];
namespace App\Models;
use IfNicolas\Sluggable\Sluggable;
use Illuminate\Database\Eloquent\Model;
class Lesson extends Model
{
use Sluggable;
protected $fillable = ['name', 'body'];
protected $slugSourceField = 'name';
}