Pārlūkot izejas kodu

added reclamation details table, model and relation

Alexander Musikhin 7 mēneši atpakaļ
vecāks
revīzija
abc4cd76ba

+ 6 - 0
app/Models/Reclamation.php

@@ -5,6 +5,7 @@ namespace App\Models;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\Relations\HasMany;
 
 class Reclamation extends Model
 {
@@ -88,4 +89,9 @@ class Reclamation extends Model
         return $this->belongsToMany(File::class, 'reclamation_act');
     }
 
+    public function details(): HasMany
+    {
+        return $this->hasMany(ReclamationDetail::class);
+    }
+
 }

+ 21 - 0
app/Models/ReclamationDetail.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class ReclamationDetail extends Model
+{
+    protected $fillable = [
+        'reclamation_id',
+        'name',
+        'quantity',
+    ];
+
+    public function reclamation(): BelongsTo
+    {
+        return $this->belongsTo(Reclamation::class);
+    }
+
+}

+ 30 - 0
database/migrations/2025_05_05_172159_create_reclamation_details_table.php

@@ -0,0 +1,30 @@
+<?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('reclamation_details', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('reclamation_id')->constrained('reclamations')->cascadeOnDelete();
+            $table->string('name');
+            $table->integer('quantity');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('reclamation_details');
+    }
+};