<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\DaUser; // Используем модель DaUser

class RegisterController extends Controller
{
    public function showRegistrationForm()
    {
        return view('registration.form');
    }

    public function register(Request $request)
    {
        $validatedData = $request->validate([
            'username' => 'required|string|max:255',
            'email' => 'required|email|unique:da_users',
            'password' => 'required|string|min:6',
        ]);

        $user = DaUser::create([
            'username' => $validatedData['username'],
            'email' => $validatedData['email'],
            'password' => bcrypt($validatedData['password']),
        ]);

        return redirect('/')->with('success', 'Konts izveidots veiksmīgi!');
    }
}
