Added registration

This commit is contained in:
Notoric 2024-06-09 22:45:57 +01:00
parent 05970bf761
commit 67abd0b6d1
4 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,25 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Validation\ValidationException;
class RegisterController extends Controller {
public function create(Request $request) {
try {
$data = $request->validate([
'name' => 'required|string|max:28|unique:users',
'email' => 'required|string|email|unique:users',
'password' => 'required|string|min:8|confirmed'
]);
$user = User::create($data);
return redirect('/');
} catch (ValidationException $e) {
return redirect()->back()->withInput($request->input())->withErrors($e->errors());
}
}
}

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>@yield('title')</title>
<link rel="stylesheet" href="{{ asset('css/default.css') }}">
@yield('head')
</head>
<body>
<main>
@yield('content')
</main>
</body>
</html>

View File

@ -0,0 +1,22 @@
@extends('default')
@section('title')
Register
@endsection
@section('content')
<h1>Register</h1>
<form method="post" action="register">
@csrf
<label for="name">Username</label>
<input type="text" name="name" id="name" value="{{ old('name') }}" required>
<label for="email">Email</label>
<input type="email" name="email" id="email" value="{{ old('email') }}" required>
<label for="password">Password</label>
<input type="password" name="password" id="password" required>
<label for="password_confirmation">Confirm Password</label>
<input type="password" name="password_confirmation" id="password_confirmation" required>
<button type="submit">Register</button>
</form>
<pre style="color: red;">{{ $errors->first() }}</pre>
@endsection

View File

@ -1,7 +1,13 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RegisterController;
Route::get('/', function () {
return view('welcome');
});
Route::get('/register', function () {
return view('register');
});
Route::post('/register', [RegisterController::class, 'create']);