Parcourir la source

schedule nullable area and district

Alexander Musikhin il y a 2 semaines
Parent
commit
8de73bfca8

+ 4 - 4
app/Http/Requests/UpdateScheduleRequest.php

@@ -25,11 +25,11 @@ class UpdateScheduleRequest extends FormRequest
             'id'                => 'nullable|exists:schedules,id',
             'installation_date' => 'required|date',
             'comment'           => 'nullable|string',
-            'area_id'           => 'required|exists:areas,id',
-            'district_id'       => 'required|exists:districts,id',
+            'area_id'           => 'nullable|exists:areas,id',
+            'district_id'       => 'nullable|exists:districts,id',
             'brigadier_id'      => 'required|exists:users,id',
-            'object_address'    =>  'required|string',
-            'object_type'       =>  'required|string',
+            'object_address'    => 'required|string',
+            'object_type'       => 'required|string',
             'mafs'              => 'required|string',
             'mafs_count'        => 'required|integer',
             'address_code'      => 'nullable|string',

+ 30 - 0
database/migrations/2025_11_19_213941_alter_schedules_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::table('schedules', function (Blueprint $table) {
+            $table->unsignedBigInteger('area_id')->nullable()->change();
+            $table->unsignedBigInteger('district_id')->nullable()->change();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('schedules', function (Blueprint $table) {
+            $table->unsignedBigInteger('area_id')->nullable(false)->change();
+            $table->unsignedBigInteger('district_id')->nullable(false)->change();
+        });
+    }
+};

+ 8 - 8
resources/views/schedule/index.blade.php

@@ -92,9 +92,9 @@
                             <td style="background: {{ $schedule->brigadier->color }}"
                                 class="align-middle code-{{ $schedule->id }}">{{ $schedule->address_code }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
-                                class="align-middle">{{ $schedule->district->shortname }}</td>
+                                class="align-middle">{{ $schedule?->district?->shortname }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
-                                class="align-middle">{{ $schedule->area->name }}</td>
+                                class="align-middle">{{ $schedule?->area?->name }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
                                 @if($schedule->order_id)
                                 <a href="{{ route('order.show', $schedule->order_id) }}">{{ $schedule->object_address }}</a>
@@ -158,12 +158,12 @@
                             <div>
                                 @include('partials.input',  ['name' => 'installation_date', 'title' => 'Дата монтажа', 'type' => 'date'])
                                 @include('partials.input',  ['name' => 'address_code', 'title' => 'Код адреса'])
-                                @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'first_empty' => true, 'required' => true])
-                                @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'required' => true, 'first_empty' => true])
-                                @include('partials.input',  ['name' => 'object_address', 'title' => 'Адрес'])
-                                @include('partials.input',  ['name' => 'object_type', 'title' => 'Тип объекта'])
-                                @include('partials.textarea', ['name' => 'mafs', 'title' => 'МАФы'])
-                                @include('partials.input',  ['name' => 'mafs_count', 'title' => 'Кол-во МАФ'])
+                                @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'first_empty' => true])
+                                @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'first_empty' => true])
+                                @include('partials.input',  ['name' => 'object_address', 'title' => 'Адрес', 'required' => true])
+                                @include('partials.input',  ['name' => 'object_type', 'title' => 'Тип объекта', 'required' => true])
+                                @include('partials.textarea', ['name' => 'mafs', 'title' => 'МАФы', 'required' => true])
+                                @include('partials.input',  ['name' => 'mafs_count', 'title' => 'Кол-во МАФ', 'type' => 'number', 'required' => true])
                                 @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'required' => true, 'first_empty' => true])
                                 @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий'])
                                 <div class="text-center">