feat: add slug field to events and implement tests for slug uniqueness per tenant

This commit is contained in:
2026-09-22 10:46:34 -03:00
parent 506f8a5176
commit 6efe8439c7
5 changed files with 129 additions and 4 deletions

View File

@@ -11,14 +11,14 @@ return new class extends Migration
public function up(): void
{
Schema::table('events', function (Blueprint $table): void {
$table->string('slug')->nullable()->after('tenant_code');
$table->string('slug')->nullable();
});
$usedSlugsByTenant = [];
foreach (DB::table('events')->orderBy('tenant_code')->orderBy('id')->get() as $event) {
$baseSlug = Str::slug((string) $event->title);
$baseSlug = $baseSlug !== '' ? mb_substr($baseSlug, 0, 240) : 'evento-'.$event->id;
$baseSlug = $baseSlug !== '' ? substr($baseSlug, 0, 240) : 'evento-'.$event->id;
$slug = $baseSlug;
$suffix = 2;