Kész migration és a hozzáadás folytatva

This commit is contained in:
Sándor Máté Magony
2025-04-04 09:00:22 +02:00
parent 31f02f023f
commit 66d2742f91
3 changed files with 82 additions and 13 deletions

View File

@@ -27,22 +27,51 @@ class HozzaadasController extends Controller
'akadalym' => 'required|boolean',
'ar' => 'required|numeric',
'nyitva' => 'required|string',
'utvonal' => 'required|string'
'utvonal' => 'required|string',
'koordinatak' => 'nullable|string'
]);
WcAdatok::create([
try {
$szelesseg = null;
$hosszusag = null;
if (!empty($validatedData['koordinatak'])) {
$koordinatak = explode(',', $validatedData['koordinatak']);
if (count($koordinatak) == 2) {
$szelesseg = trim($koordinatak[0]);
$hosszusag = trim($koordinatak[1]);
if (!is_numeric($szelesseg) || !is_numeric($hosszusag)) {
return response() -> json([
'message' => 'Érvénytelen a koordináták formátuma'
], 422);
}
}
}
$mosdo = WcAdatok::create([
'nev' => $validatedData['nev'],
'kerulet' => $validatedData['kerulet'],
'kozeli_megall' => $validatedData['kozeli_megall'],
'akadalym' => $validatedData['akadalym'],
'ar' => $validatedData['ar'],
'nyitva' => $validatedData['nyitva'],
'nyitva' => $validatedData['nyitva']
'utvonal' => $validatedData['utvonal'],
'szel_koord' => $szelesseg,
'hossz_koord' => $hosszusag
]);
return response() -> json([
'message' => 'Sikeres rögzítés'
'message' => 'Sikeres rögzítés',
'data' => $mosdo
], 201);
} catch (\Exception $e) {
return response() -> json([
'message' => 'Hiba történt a mentés során',
'error' => $e -> getMessage()
], 500);
}
}
/**

View File

@@ -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
{
public function up(): void
{
Schema::create('wc_adatok', function (Blueprint $table) {
$table->id();
$table->string('nev', 250);
$table->string('kerulet', 250);
$table->string('kozeli_megall', 250);
$table->boolean('akadalym');
$table->integer('ar');
$table->string('nyitva', 250);
$table->double('hossz_koord')->nullable();
$table->double('szel_koord')->nullable();
$table->string('utvonal', 1000);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('wc_adatok');
}
};

View File

@@ -77,6 +77,16 @@ export default function HozzaadForm() {
/>
<div className="flex items-center space-x-2">
<label className="text-gray-700">Koordináták:</label>
<ToolTip children={"❔"} text={"A koordinátákat a helyre kattintva tudja a vágólapra másolni [Jobbklikk ➡ Koordináták (pl. 41.1212, 21.3213)]"} />
</div>
<input
type="text"
placeholder="Koordináták"
className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
<button
type="submit"
className="w-full bg-yellow-600 text-white py-2 rounded-lg hover:bg-yellow-700 transition">