Files
PeePal/Backend/laravel9/app/Http/Controllers/UserController.php
Sándor Máté Magony 2d71603962 Majdnem kész
2025-04-24 15:38:31 +02:00

76 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validatedData = $request->validate([
'nev' => 'required|string',
'email' => 'required|email|unique:felhasznalok',
'felh_nev' => 'required|string|unique:felhasznalok',
'jelszo' => 'required|string|min:6',
'is_admin' => 'boolean'
]);
try {
$felhasznalo = User::create([
'nev' => $validatedData['nev'],
'email' => $validatedData['email'],
'felh_nev' => $validatedData['felh_nev'],
'jelszo' => $validatedData['jelszo'], // Will be hashed by mutator
'is_admin' => $validatedData['is_admin'] ?? false
]);
return response()->json([
'message' => 'Sikeres rögzítés',
'data' => $felhasznalo
], 201);
} catch (\Exception $e) {
return response()->json([
'message' => 'Hiba történt a mentés során',
'error' => $e->getMessage()
], 500);
}
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}