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

73 lines
1.8 KiB
PHP
Raw Normal View History

2016-06-20 13:35:59 +00:00
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
2019-11-08 12:08:34 +00:00
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
2016-06-20 13:35:59 +00:00
2019-11-08 12:08:34 +00:00
class RegisterController extends Controller
2016-06-20 13:35:59 +00:00
{
/*
|--------------------------------------------------------------------------
2019-11-08 12:08:34 +00:00
| Register Controller
2016-06-20 13:35:59 +00:00
|--------------------------------------------------------------------------
|
2019-11-08 12:08:34 +00:00
| 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.
2016-06-20 13:35:59 +00:00
|
*/
2019-11-08 12:08:34 +00:00
use RegistersUsers;
2016-06-20 13:35:59 +00:00
/**
2019-11-08 12:08:34 +00:00
* Where to redirect users after registration.
2016-06-20 13:35:59 +00:00
*
* @var string
*/
2019-11-08 12:08:34 +00:00
protected $redirectTo = '/home';
2016-06-20 13:35:59 +00:00
/**
2019-11-08 12:08:34 +00:00
* Create a new controller instance.
2016-06-20 13:35:59 +00:00
*
* @return void
*/
public function __construct()
{
2019-11-08 12:08:34 +00:00
$this->middleware('guest');
2016-06-20 13:35:59 +00:00
}
/**
* 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, [
2019-11-08 12:08:34 +00:00
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
2016-06-20 13:35:59 +00:00
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
2019-11-08 12:08:34 +00:00
* @return \App\User
2016-06-20 13:35:59 +00:00
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
2019-11-08 12:08:34 +00:00
'password' => Hash::make($data['password']),
2016-06-20 13:35:59 +00:00
]);
}
}