2019-12-08 21:41:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
|
|
|
|
use App\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Illuminate\Foundation\Auth\RegistersUsers;
|
2019-12-09 16:22:29 +01:00
|
|
|
use Illuminate\Http\Request;
|
2019-12-08 21:41:24 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
protected $redirectTo = '/home';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('guest');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-09 16:22:29 +01:00
|
|
|
* Create a new user instance after a valid registration.
|
2019-12-08 21:41:24 +01:00
|
|
|
*
|
|
|
|
* @param array $data
|
2019-12-09 16:22:29 +01:00
|
|
|
* @return \App\User
|
2019-12-08 21:41:24 +01:00
|
|
|
*/
|
2019-12-09 16:22:29 +01:00
|
|
|
protected function create(Request $request)
|
2019-12-08 21:41:24 +01:00
|
|
|
{
|
2019-12-09 16:22:29 +01:00
|
|
|
$validator = Validator::make($request->all(), [
|
2019-12-08 21:41:24 +01:00
|
|
|
'name' => ['required', 'string', 'max:255'],
|
|
|
|
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
|
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
|
|
]);
|
|
|
|
|
2019-12-09 16:22:29 +01:00
|
|
|
if ($validator->fails()) {
|
|
|
|
return response()->json(["message " => "Validation failed."], 404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = User::create([
|
|
|
|
'name' => $request->name,
|
|
|
|
'email' => $request->email,
|
|
|
|
'password' => Hash::make($request->password),
|
2019-12-08 21:41:24 +01:00
|
|
|
]);
|
2019-12-09 16:22:29 +01:00
|
|
|
|
|
|
|
return response()->json($user, 201);
|
2019-12-08 21:41:24 +01:00
|
|
|
}
|
|
|
|
}
|