Prechádzať zdrojové kódy

created reclamation model with relations

Alexander Musikhin 7 mesiacov pred
rodič
commit
a27d28ab3f

+ 10 - 0
app/Http/Controllers/ReclamationController.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+
+class ReclamationController extends Controller
+{
+    //
+}

+ 51 - 0
app/Models/Reclamation.php

@@ -0,0 +1,51 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+
+class Reclamation extends Model
+{
+    protected $fillable = [
+        'order_id',
+        'user_id',
+        'reason',
+        'guarantee',
+        'whats_done',
+        'create_date',
+        'finish_date',
+    ];
+
+    public function order(): BelongsTo
+    {
+        return $this->belongsTo(Order::class);
+    }
+
+    public function user(): BelongsTo
+    {
+        return $this->belongsTo(User::class);
+    }
+
+    public function photos_before(): BelongsToMany
+    {
+        return $this->belongsToMany(File::class, 'reclamation_photo_before');
+    }
+
+    public function photos_after(): BelongsToMany
+    {
+        return $this->belongsToMany(File::class, 'reclamation_photo_after');
+    }
+
+    public function documents(): BelongsToMany
+    {
+        return $this->belongsToMany(File::class, 'reclamation_document');
+    }
+
+    public function acts(): BelongsToMany
+    {
+        return $this->belongsToMany(File::class, 'reclamation_act');
+    }
+
+}

+ 34 - 0
database/migrations/2025_04_30_172039_create_reclamations_table.php

@@ -0,0 +1,34 @@
+<?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('reclamations', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('order_id')->constrained('orders')->restrictOnDelete();
+            $table->foreignId('user_id')->constrained('users')->restrictOnDelete();
+            $table->date('create_date')->useCurrent();
+            $table->date('finish_date')->nullable();
+            $table->text('reason')->nullable();
+            $table->text('guarantee')->nullable();
+            $table->text('whats_done')->nullable();
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('reclamations');
+    }
+};

+ 28 - 0
database/migrations/2025_04_30_180837_create_reclamation_photo_before_table.php

@@ -0,0 +1,28 @@
+<?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_photo_before', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('reclamation_id')->constrained('reclamations')->cascadeOnDelete();
+            $table->foreignId('file_id')->constrained('files')->cascadeOnDelete();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('reclamation_photo_before');
+    }
+};

+ 28 - 0
database/migrations/2025_04_30_180844_create_reclamation_photo_after_table.php

@@ -0,0 +1,28 @@
+<?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_photo_after', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('reclamation_id')->constrained('reclamations')->cascadeOnDelete();
+            $table->foreignId('file_id')->constrained('files')->cascadeOnDelete();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('reclamation_photo_after');
+    }
+};

+ 28 - 0
database/migrations/2025_04_30_180856_create_reclamation_document_table.php

@@ -0,0 +1,28 @@
+<?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_document', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('reclamation_id')->constrained('reclamations')->cascadeOnDelete();
+            $table->foreignId('file_id')->constrained('files')->cascadeOnDelete();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('reclamation_document');
+    }
+};

+ 28 - 0
database/migrations/2025_04_30_181003_create_reclamation_act_table.php

@@ -0,0 +1,28 @@
+<?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_act', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('reclamation_id')->constrained('reclamations')->cascadeOnDelete();
+            $table->foreignId('file_id')->constrained('files')->cascadeOnDelete();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('reclamation_act');
+    }
+};