summaryrefslogtreecommitdiff
path: root/workbench/database
diff options
context:
space:
mode:
Diffstat (limited to 'workbench/database')
-rw-r--r--workbench/database/factories/CategoryFactory.php33
-rw-r--r--workbench/database/migrations/2025_03_27_211321_create_categories_table.php38
2 files changed, 71 insertions, 0 deletions
diff --git a/workbench/database/factories/CategoryFactory.php b/workbench/database/factories/CategoryFactory.php
new file mode 100644
index 0000000..756c22a
--- /dev/null
+++ b/workbench/database/factories/CategoryFactory.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Workbench\Database\Factories;
+
+use Illuminate\Database\Eloquent\Factories\Factory;
+use Workbench\App\Models\Category;
+
+/**
+ * @template TModel of \Workbench\App\Models\Category
+ *
+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<TModel>
+ */
+class CategoryFactory extends Factory
+{
+ /**
+ * The name of the factory's corresponding model.
+ *
+ * @var class-string<TModel>
+ */
+ protected $model = Category::class;
+
+ /**
+ * Define the model's default state.
+ *
+ * @return array<string, mixed>
+ */
+ public function definition(): array
+ {
+ return [
+ 'name' => fake()->text(20),
+ ];
+ }
+}
diff --git a/workbench/database/migrations/2025_03_27_211321_create_categories_table.php b/workbench/database/migrations/2025_03_27_211321_create_categories_table.php
new file mode 100644
index 0000000..5a75f30
--- /dev/null
+++ b/workbench/database/migrations/2025_03_27_211321_create_categories_table.php
@@ -0,0 +1,38 @@
+<?php
+
+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::create('categories', function (Blueprint $table) {
+ $table->id();
+ $table->string('name');
+ $table->timestamps();
+ $table->softDeletes();
+ });
+
+ Schema::table('products', function (Blueprint $table) {
+ $table->foreignId('category_id');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('categories');
+
+ Schema::table('products', function (Blueprint $table) {
+ $table->dropColumn('category_id');
+ });
+
+ }
+};