1. Go to this page and download the library: Download aesircloud/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/ */
aesircloud / sluggable example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use AesirCloud\Sluggable\Traits\Sluggable;
class Post extends Model
{
use Sluggable;
protected $fillable = ['title', 'slug'];
protected $slugSource = 'title'; // or 'description', or any other field
}
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('posts', function (Blueprint $table) {
$table->string('slug')->unique()->after('title');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('slug');
});
}
};