Kaynağa Gözat

added file model

Alexander Musikhin 7 ay önce
ebeveyn
işleme
8a1aa33761

+ 22 - 0
app/Models/File.php

@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+
+class File extends Model
+{
+    protected $fillable = [
+        'user_id',
+        'original_name',
+        'mime_type',
+        'path',
+    ];
+
+    public function user(): BelongsTo
+    {
+        return $this->belongsTo(User::class);
+    }
+
+}

+ 16 - 0
app/Models/Order.php

@@ -133,6 +133,22 @@ class Order extends Model
         return $this->belongsTo(OrderStatus::class);
     }
 
+    public function photos(): BelongsToMany
+    {
+        return $this->belongsToMany(File::class, 'order_file', 'order_id', 'file_id');
+    }
+
+    public function documents(): BelongsToMany
+    {
+        return $this->belongsToMany(File::class, 'order_file', 'order_id', 'file_id');
+    }
+
+    public function statements(): BelongsToMany
+    {
+        return $this->belongsToMany(File::class, 'order_file', 'order_id', 'file_id');
+    }
+
+
 
     public function getNeeds(): array
     {

+ 31 - 0
database/migrations/2025_04_25_194007_create_files_table.php

@@ -0,0 +1,31 @@
+<?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('files', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('user_id')->constrained('users')->restrictOnDelete();
+            $table->string('original_name');
+            $table->string('mime_type');
+            $table->string('path');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('files');
+    }
+};

+ 28 - 0
database/migrations/2025_04_25_195408_create_order_file_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('order_file', function (Blueprint $table) {
+            $table->id();
+            $table->foreignId('order_id')->constrained('orders');
+            $table->foreignId('file_id')->constrained('files');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('order_file');
+    }
+};

+ 9 - 0
resources/views/orders/show.blade.php

@@ -37,6 +37,15 @@
                 <div>Менеджер: {{ $order->user->name }}, тел. {{ $order->user->phone }}</div>
                 <div>Название группы в ТГ: {{ $order->tg_group_name }}</div>
                 <div>Ссылка на группу в ТГ: {{ $order->tg_group_link }}</div>
+                <div class="photo">
+                    Фотографии
+                    <form action="" enctype="multipart/form-data" method="post">
+                        @csrf
+                        <input type="file" multiple name="photo[]" class="form-control form-control-sm" accept="jpg,jpeg,png">
+                        <button type="submit" class="btn btn-sm btn-primary">Загрузить</button>
+                    </form>
+                    @dump($order->photo)
+                </div>
 
             </div>
             <div class="col-xl-9">

+ 1 - 1
resources/views/products_sku/edit.blade.php

@@ -6,7 +6,7 @@
 
         <form class="row" action="{{ route('product_sku.update', $product_sku) }}" method="post">
             <div class="col-xxl-6">
-                <h4>Заказ МАФ на складе</h4>
+                <h4>МАФ на складе</h4>
                 @csrf
 
                 <input type="hidden" id="product_id" name="product_id" value="{{ $product_sku->product_id }}">

+ 1 - 1
resources/views/products_sku/index.blade.php

@@ -4,7 +4,7 @@
 
     <div class="row mb-3">
         <div class="col-6">
-            <h3>Заказы МАФ</h3>
+            <h3>МАФ</h3>
         </div>
         <div class="col-6 text-end">
 {{--            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addModal">--}}