RegisterController.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Shop\Customers\Customer;
  4. use App\Http\Controllers\Controller;
  5. use App\Shop\Customers\Repositories\Interfaces\CustomerRepositoryInterface;
  6. use App\Shop\Customers\Requests\CreateCustomerRequest;
  7. use App\Shop\Customers\Requests\RegisterCustomerRequest;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Support\Facades\Auth;
  10. use Illuminate\Support\Facades\Validator;
  11. use Illuminate\Foundation\Auth\RegistersUsers;
  12. class RegisterController extends Controller
  13. {
  14. /*
  15. |--------------------------------------------------------------------------
  16. | Register Controller
  17. |--------------------------------------------------------------------------
  18. |
  19. | This controller handles the registration of new users as well as their
  20. | validation and creation. By default this controller uses a trait to
  21. | provide this functionality without requiring any additional code.
  22. |
  23. */
  24. use RegistersUsers;
  25. /**
  26. * Where to redirect users after registration.
  27. *
  28. * @var string
  29. */
  30. protected $redirectTo = '/accounts';
  31. private $customerRepo;
  32. /**
  33. * Create a new controller instance.
  34. * @param CustomerRepositoryInterface $customerRepository
  35. */
  36. public function __construct(CustomerRepositoryInterface $customerRepository)
  37. {
  38. $this->middleware('guest');
  39. $this->customerRepo = $customerRepository;
  40. }
  41. /**
  42. * Create a new user instance after a valid registration.
  43. *
  44. * @param array $data
  45. * @return Customer
  46. */
  47. protected function create(array $data)
  48. {
  49. return $this->customerRepo->createCustomer($data);
  50. }
  51. /**
  52. * @param RegisterCustomerRequest $request
  53. * @return \Illuminate\Http\RedirectResponse
  54. */
  55. public function register(RegisterCustomerRequest $request)
  56. {
  57. $customer = $this->create($request->except('_method', '_token'));
  58. Auth::login($customer);
  59. return redirect()->route('accounts');
  60. }
  61. }