sototh пре 1 месец
родитељ
комит
336f924e55

+ 4 - 4
.env.example

@@ -4,10 +4,10 @@ APP_KEY=
 APP_DEBUG=true
 APP_URL=http://localhost
 
-APP_LOCALE=en
-APP_FALLBACK_LOCALE=en
-APP_FAKER_LOCALE=en_US
-
+APP_LOCALE=ru
+APP_FALLBACK_LOCALE=ru
+APP_FAKER_LOCALE=ru
+APP_TIMEZONE=Asia/Irkutsk
 APP_MAINTENANCE_DRIVER=file
 # APP_MAINTENANCE_STORE=database
 

+ 54 - 0
app/Http/Controllers/FormController.php

@@ -0,0 +1,54 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Storage;
+use Illuminate\Support\Str;
+
+class FormController extends Controller
+{
+    public function showForm()
+    {
+        return view('form');
+    }
+
+    public function submitForm(Request $request)
+    {
+        $validated = $request->validate([
+            'name' => 'required|min:2|max:100',
+            'email' => 'required|email',
+            'phone' => 'required|digits:11',
+            'gender' => 'boolean',
+            'message' => 'required|min:10|max:1000',
+        ]);
+        $filename = 'form-data-' . Str::uuid() . '.json';
+        Storage::put("form-data/{$filename}", json_encode([
+            'id' => Str::uuid(),
+            'name' => $validated['name'],
+            'email' => $validated['email'],
+            'phone' => $validated['phone'],
+            'gender' => array_key_exists('gender', $validated) ? $validated['gender'] : 0,
+            'message' => $validated['message'],
+            'submitted_at' => now()->timezone('Asia/Irkutsk')->toDateISOString(),
+        ], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
+
+        return redirect()->route('form.show')
+            ->with('success', 'Данные успешно сохранены!');
+    }
+
+    public function showData()
+    {
+        $files = Storage::files('form-data');
+        $data = [];
+
+        foreach ($files as $file) {
+            if (pathinfo($file, PATHINFO_EXTENSION) === 'json') {
+                $content = Storage::get($file);
+                $data[] = json_decode($content, true);
+            }
+        }
+
+        return view('data', compact('data'));
+    }
+}

+ 47 - 0
resources/views/data.blade.php

@@ -0,0 +1,47 @@
+@extends('layouts.app')
+
+@section('title', 'Просмотр данных')
+
+@section('content')
+<div>
+    <div>
+        <h4>Все отправленные данные</h4>
+    </div>
+    <div>
+        @if(empty($data))
+            <div>
+                Данные отсутствуют. <a href="{{ route('form.show') }}">Отправьте форму</a> чтобы добавить данные.
+            </div>
+        @else
+            <div>
+                <table>
+                    <thead>
+                        <tr>
+                            <th>ID</th>
+                            <th>Имя</th>
+                            <th>Email</th>
+                            <th>Телефон</th>
+                            <th>Пол</th>
+                            <th>Сообщение</th>
+                            <th>Дата отправки</th>
+                        </tr>
+                    </thead>
+                    <tbody>
+                        @foreach($data as $item)
+                        <tr>
+                            <td><small>{{ substr($item['id'], 0, 8) }}...</small></td>
+                            <td>{{ $item['name'] }}</td>
+                            <td>{{ $item['email'] }}</td>
+                            <td>{{ $item['phone'] }}</td>
+                            <td>{{ $item['gender'] ? 'Male' : 'female' }}</td>
+                            <td>{{ Str::limit($item['message'], 50) }}</td>
+                            <td>{{ \Carbon\Carbon::parse($item['submitted_at'])->timezone('Asia/Irkutsk')->format('d.m.Y H:i') }}</td>
+                        </tr>
+                        @endforeach
+                    </tbody>
+                </table>
+            </div>
+        @endif
+    </div>
+</div>
+@endsection

+ 66 - 0
resources/views/form.blade.php

@@ -0,0 +1,66 @@
+@extends('layouts.app')
+
+@section('title', 'Форма отправки')
+
+@section('content')
+<div>
+    <div>
+        <div>
+            <div>
+                <h4>Форма обратной связи</h4>
+            </div>
+            <div>
+                <form method="POST" action="{{ route('form.submit') }}">
+                    @csrf
+                    
+                    <div>
+                        <label for="name">Имя *</label>
+                        <input type="text"   
+                               id="name" name="name" value="{{ old('name') }}" required>
+                        @error('name')
+                            <div>{{ $message }}</div>
+                        @enderror
+                    </div>
+
+                    <div>
+                        <label for="email">Email *</label>
+                        <input type="email"   
+                               id="email" name="email" value="{{ old('email') }}" required>
+                        @error('email')
+                            <div>{{ $message }}</div>
+                        @enderror
+                    </div>
+
+                    <div>
+                        <label for="phone">Phone *</label>
+                        <input type="phone"   
+                               id="phone" name="phone" value="{{ old('phone') }}" required>
+                        @error('phone')
+                            <div>{{ $message }}</div>
+                        @enderror
+                    </div>
+
+                    <div>
+                        <label for="gender">gender *</label>
+                        <input type="checkbox" name="gender" value="1" @checked(old("terms"))>
+                        @error('gender')
+                            <div>{{ $message }}</div>
+                        @enderror
+                    </div>
+
+                    <div>
+                        <label for="message">Сообщение *</label>
+                        <textarea   
+                                  id="message" name="message" rows="5" required>{{ old('message') }}</textarea>
+                        @error('message')
+                            <div>{{ $message }}</div>
+                        @enderror
+                    </div>
+
+                    <button type="submit">Отправить</button>
+                </form>
+            </div>
+        </div>
+    </div>
+</div>
+@endsection

+ 49 - 0
resources/views/layouts/app.blade.php

@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html lang="ru">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>@yield('title') - Это мое приложение</title>
+</head>
+<body>
+    <header>
+        <div>
+            <div>
+                <div>
+                    <img src="https://cdn-icons-png.flaticon.com/512/2028/2028378.png" alt="Logo" height="40">
+                    <h4>Laravel =-3</h4>
+                </div>
+                <nav>
+                    <ul>
+                        <li>
+                            <a href="{{ route('form.show') }}">Форма</a>
+                        </li>
+        <li>
+                            <a href="{{ route('data.show') }}">Данные</a>
+                        </li>
+                    </ul>
+                </nav>
+            </div>
+        </div>
+    </header>
+
+    <main>
+        <div>
+            @if(session('success'))
+                <div role="alert">
+                    {{ session('success') }}
+                    <button type="button"   data-bs-dismiss="alert"></button>
+                </div>
+            @endif
+
+            @yield('content')
+        </div>
+    </main>
+
+    <footer>
+        <div>
+            <p>&copy; {{ date('Y') }} Laravel App. Ну, допустим какой-то текст.</p>
+        </div>
+    </footer>
+</body>
+</html>

+ 5 - 0
routes/web.php

@@ -1,7 +1,12 @@
 <?php
 
 use Illuminate\Support\Facades\Route;
+use App\Http\Controllers\FormController;
 
 Route::get('/', function () {
     return view('welcome');
 });
+
+Route::get('/form', [FormController::class, 'showForm'])->name('form.show');
+Route::post('/form', [FormController::class, 'submitForm'])->name('form.submit');
+Route::get('/data', [FormController::class, 'showData'])->name('data.show');