diff --git a/app/Http/Controllers/admin/Catalog/FacultyController.php b/app/Http/Controllers/admin/Catalog/FacultyController.php index 269ed9d..ae0f123 100644 --- a/app/Http/Controllers/admin/Catalog/FacultyController.php +++ b/app/Http/Controllers/admin/Catalog/FacultyController.php @@ -31,7 +31,14 @@ class FacultyController extends Controller { $validated = $request->validated(); - $slug = $validated['slug'] === null ? Str::slug($validated['name']) : $validated['slug']; + if ($validated['slug'] === null) { + $transliterationSlug = Str::slug($validated['name']); + $randomNumber = random_int(100, 999); + $slug = "{$transliterationSlug}-{$randomNumber}"; + } else { + $slug = $validated['slug']; + } + $faculty = new Faculty(); $faculty->name = $validated['name']; $faculty->description = $validated['description']; diff --git a/database/migrations/2024_02_07_073254_create_faculties_table.php b/database/migrations/2024_02_07_073254_create_faculties_table.php index 557e23d..055f47c 100644 --- a/database/migrations/2024_02_07_073254_create_faculties_table.php +++ b/database/migrations/2024_02_07_073254_create_faculties_table.php @@ -10,10 +10,10 @@ return new class extends Migration { Schema::create('faculties', function (Blueprint $table) { $table->id(); - $table->string('name'); + $table->string('name')->unique(); $table->text('description')->nullable(); $table->integer('position'); - $table->string('slug'); + $table->string('slug')->unique(); $table->foreignId('educational_institution_id')->constrained('educational_institutions'); $table->timestamps(); }); diff --git a/resources/views/admin/catalog/faculty/create.blade.php b/resources/views/admin/catalog/faculty/create.blade.php index ca60d06..fb3a279 100644 --- a/resources/views/admin/catalog/faculty/create.blade.php +++ b/resources/views/admin/catalog/faculty/create.blade.php @@ -5,14 +5,17 @@