forked from magonysandormate/PeePal
Majdnem kész
This commit is contained in:
76
Backend/laravel9/app/Http/Controllers/UserController.php
Normal file
76
Backend/laravel9/app/Http/Controllers/UserController.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?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)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user