clrghouz/app/Http/Controllers/Auth/RegisterController.php

74 lines
1.9 KiB
PHP
Raw Normal View History

2018-11-15 10:45:49 +00:00
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
2021-05-03 12:53:40 +00:00
use App\Providers\RouteServiceProvider;
use App\Models\User;
use Illuminate\Foundation\Auth\RegistersUsers;
2018-11-15 10:45:49 +00:00
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* @var string
*/
2021-05-03 12:53:40 +00:00
protected $redirectTo = RouteServiceProvider::HOME;
2018-11-15 10:45:49 +00:00
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
2021-06-13 13:00:26 +00:00
'name' => ['required', 'string', 'min:3', 'max:255'],
2018-11-15 10:45:49 +00:00
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
2021-05-03 12:53:40 +00:00
'password' => ['required', 'string', 'min:8', 'confirmed'],
2018-11-15 10:45:49 +00:00
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
2021-05-03 12:53:40 +00:00
* @return \App\Models\User
2018-11-15 10:45:49 +00:00
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}