瀏覽代碼

Added delete operation

AItEKS 2 周之前
父節點
當前提交
599a2060f4

+ 7 - 0
form-app-with-data/app/Http/Controllers/FormController.php

@@ -64,4 +64,11 @@ class FormController extends Controller
 
         return redirect()->route('admin.index')->with('success', 'Данные обновлены!');
     }
+
+    public function delete(ContactMessage $submission)
+    {
+        $submission -> delete();
+
+        return redirect()->route('admin.index')->with('success', 'Запись удалена!');
+    }
 }

+ 4 - 0
form-app-with-data/app/Models/ContactMessage.php

@@ -4,15 +4,19 @@ namespace App\Models;
 
 use Illuminate\Database\Eloquent\Factories\HasFactory;
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
 
 class ContactMessage extends Model
 {
     //
     use HasFactory;
+    use SoftDeletes;
 
     protected $fillable = [
         'name',
         'email',
         'message',
     ];
+
+    protected $dates = ['deleted_at'];
 }

+ 30 - 0
form-app-with-data/database/migrations/2025_12_08_110321_add_deleted_at_to_contact_messages_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('contact_messages', function (Blueprint $table) {
+            //
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('contact_messages', function (Blueprint $table) {
+            //
+            $table->dropSoftDeletes();
+        });
+    }
+};

+ 83 - 19
form-app-with-data/resources/views/admin/index.blade.php

@@ -133,6 +133,51 @@
             color: #155724;
             border: 1px solid #c3e6cb;
         }
+
+        /* Стили для кнопок действий */
+        .action-btn {
+            padding: 5px 10px;
+            font-size: 16px;
+            border: none;
+            border-radius: 5px;
+            cursor: pointer;
+            text-decoration: none;
+            display: inline-block;
+            margin: 0 2px;
+            transition: all 0.2s;
+        }
+
+        .action-btn:hover {
+            transform: scale(1.1);
+            box-shadow: 0 2px 8px rgba(0,0,0,0.2);
+        }
+
+        .btn-view {
+            background: #3498db;
+            color: white;
+        }
+
+        .btn-view:hover {
+            background: #2980b9;
+        }
+
+        .btn-edit {
+            background: #f1c40f;
+            color: white;
+        }
+
+        .btn-edit:hover {
+            background: #f39c12;
+        }
+
+        .btn-delete {
+            background: #e74c3c;
+            color: white;
+        }
+
+        .btn-delete:hover {
+            background: #c0392b;
+        }
         
         @media (max-width: 768px) {
             .container {
@@ -147,6 +192,11 @@
             .message-cell {
                 max-width: 150px;
             }
+            .action-btn {
+                font-size: 14px;
+                padding: 4px 8px;
+                margin: 1px;
+            }
         }
     </style>
 </head>
@@ -161,15 +211,6 @@
             </div>
         @endif
 
-        <div class="header-actions">
-            <div class="count-badge">
-                Всего записей: {{ $submissions->count() }}
-            </div>
-            <a href="{{ route('form') }}" class="btn btn-secondary">
-                ← Вернуться к форме
-            </a>
-        </div>
-
         <div class="table-wrapper">
             @if($submissions->count() > 0)
                 <table>
@@ -180,35 +221,58 @@
                             <th>Email</th>
                             <th>Сообщение</th>
                             <th>Дата отправки</th>
-                            <th style="text-align: right;">Действия</th> {{-- 1. Новый заголовок --}}
+                            <th style="text-align: right;">Действия</th>
                         </tr>
                     </thead>
                     <tbody>
                         @foreach($submissions as $submission)
                             <tr>
-                                {{-- Ваши существующие ячейки --}}
-                                <td>{{ $loop->iteration }}</td> {{-- $loop->iteration лучше, чем $index + 1 --}}
+                                <td>{{ $loop->iteration }}</td>
                                 <td>{{ $submission->name }}</td>
                                 <td class="email-cell">{{ $submission->email }}</td>
                                 <td class="message-cell">{{ $submission->message }}</td>
                                 <td class="date-cell">
                                     {{ $submission->created_at->format('d.m.Y H:i') }}
                                 </td>
-
-                                </td>
-
                                 <td style="text-align: right; white-space: nowrap;">
-                                    
-                                    <a href="{{ route('admin.show', $submission->id) }}" class="btn" style="padding: 5px 10px; font-size: 12px; background: #3498db;" title="Просмотр">👁️</a>
+                                    {{-- Просмотр --}}
+                                    <a href="{{ route('admin.show', $submission->id) }}" 
+                                       class="action-btn btn-view" 
+                                       title="Просмотр">
+                                        👁️
+                                    </a>
+
+                                    {{-- Редактирование --}}
+                                    <a href="{{ route('admin.edit', $submission->id) }}" 
+                                       class="action-btn btn-edit" 
+                                       title="Редактировать">
+                                        ✏️
+                                    </a>
 
-                                    <a href="{{ route('admin.edit', $submission->id) }}" class="btn" style="padding: 5px 10px; font-size: 12px; background: #f1c40f;" title="Редактировать">✏️</a>
+                                    {{-- Удаление --}}
+                                    <form action="{{ route('admin.delete', $submission) }}" 
+                                          method="POST" 
+                                          style="display: inline;"
+                                          onsubmit="return confirm('⚠️ Вы уверены?\n\nЗапись будет перемещена в корзину.')">
+                                        @csrf
+                                        @method('DELETE')
+                                        <button type="submit" 
+                                                class="action-btn btn-delete" 
+                                                title="Удалить">
+                                            🗑️
+                                        </button>
+                                    </form>
                                 </td>
                             </tr>
                         @endforeach
                     </tbody>
                 </table>
             @else
-                {{-- Ваш блок empty-state --}}
+                <div class="empty-state">
+                    <div class="empty-state-icon">📭</div>
+                    <h3>Пока нет отправленных данных</h3>
+                    <p style="margin-top: 10px;">Заполните форму, чтобы увидеть данные здесь</p>
+                </div>
             @endif
         </div>
     </div>

+ 2 - 1
form-app-with-data/routes/web.php

@@ -10,4 +10,5 @@ Route::post('/form-submit', [FormController::class, 'submit'])->name('form.submi
 Route::get('/admin', [FormController::class, 'showData'])->name('admin.index');
 Route::get('/admin/{submission}', [FormController::class, 'show'])->name('admin.show');
 Route::get('/admin/{submission}/edit', [FormController::class, 'edit'])->name('admin.edit');
-Route::put('/admin/{submission}', [FormController::class, 'update'])->name('admin.update');
+Route::put('/admin/{submission}', [FormController::class, 'update'])->name('admin.update');
+Route::delete('/admin/{submission}', [FormController::class, 'delete'])->name('admin.delete');