request
<?php
namespace AppHttpControllersAuth;
use AppModelsUser;
use AppModelsAdmin;
use AppModelsBlogger;
use AppHttpControllersController;
use IlluminateSupportFacadesHash;
use IlluminateSupportFacadesValidator;
use IlluminateFoundationAuthRegistersUsers;
use IlluminateHttpRequest;
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');
$this->middleware('guest:admin');
$this->middleware('guest:blogger');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return IlluminateContractsValidationValidator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* @return IlluminateContractsViewFactory|IlluminateViewView
*/
public function showAdminRegisterForm()
{
return view('auth.register', ['url' => 'admin']);
}
/**
* @return IlluminateContractsViewFactory|IlluminateViewView
*/
public function showBloggerRegisterForm()
{
return view('auth.register', ['url' => 'blogger']);
}
/**
* @param array $data
*
* @return mixed
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
/**
* @param Request $request
*
* @return IlluminateHttpRedirectResponse
*/
protected function createAdmin(Request $request)
{
$this->validator($request->all())->validate();
Admin::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
return redirect()->intended('login/admin');
}
/**
* @param Request $request
*
* @return IlluminateHttpRedirectResponse
*/
protected function createBlogger(Request $request)
{
$this->validator($request->all())->validate();
Blogger::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
return redirect()->intended('login/blogger');
}
}