RegisterController.php
1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
// Контроллер регистрации пользователя
class RegisterController extends Controller
{
public function __construct() {
$this->middleware('guest');
}
// Форма регистрации
public function register() {
return view('auth.register');
}
// Создание пользователя
public function create(Request $request) {
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:8|confirmed',
]);
User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
return redirect()
->route('auth.login')
->with('success', 'Вы успешно зарегистрировались');
}
}