sarga/packages/Webkul/API/Http/Controllers/Shop/CustomerController.php

84 lines
2.3 KiB
PHP
Raw Normal View History

2019-05-07 11:36:21 +00:00
<?php
namespace Webkul\API\Http\Controllers\Shop;
use Illuminate\Support\Facades\Event;
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Customer\Repositories\CustomerGroupRepository;
2019-05-07 11:36:21 +00:00
class CustomerController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* Repository object
*
2020-03-05 05:34:57 +00:00
* @var \Webkul\Customer\Repositories\CustomerRepository
2019-05-07 11:36:21 +00:00
*/
protected $customerRepository;
/**
* Repository object
*
2020-03-05 05:34:57 +00:00
* @var \Webkul\Customer\Repositories\CustomerGroupRepository
2019-05-07 11:36:21 +00:00
*/
protected $customerGroupRepository;
/**
* Create a new controller instance.
*
2020-03-05 14:19:14 +00:00
* @param \Webkul\Customer\Repositories\CustomerRepository $customerRepository
2020-03-05 05:34:57 +00:00
* @param \Webkul\Customer\Repositories\CustomerGroupRepository $customerGroupRepository
* @return void
*/
public function __construct(
CustomerRepository $customerRepository,
CustomerGroupRepository $customerGroupRepository
) {
2019-05-07 11:36:21 +00:00
$this->_config = request('_config');
$this->customerRepository = $customerRepository;
$this->customerGroupRepository = $customerGroupRepository;
2019-05-07 11:36:21 +00:00
}
/**
* Method to store user's sign up form data to DB.
*
2020-03-05 05:34:57 +00:00
* @return \Illuminate\Http\Response
2019-05-07 11:36:21 +00:00
*/
public function create()
{
request()->validate([
'first_name' => 'required',
2020-02-19 11:24:04 +00:00
'last_name' => 'required',
'email' => 'email|required|unique:customers,email',
2020-03-04 06:32:53 +00:00
'password' => 'confirmed|min:6|required',
2019-05-07 11:36:21 +00:00
]);
$data = request()->input();
$data = array_merge($data, [
2020-02-19 11:24:04 +00:00
'password' => bcrypt($data['password']),
'channel_id' => core()->getCurrentChannel()->id,
2020-03-04 06:32:53 +00:00
'is_verified' => 1,
2019-05-07 11:36:21 +00:00
]);
$data['customer_group_id'] = $this->customerGroupRepository->findOneWhere(['code' => 'general'])->id;
2019-12-24 14:01:13 +00:00
Event::dispatch('customer.registration.before');
2019-05-07 11:36:21 +00:00
$customer = $this->customerRepository->create($data);
2019-12-24 14:01:13 +00:00
Event::dispatch('customer.registration.after', $customer);
2019-05-07 11:36:21 +00:00
return response()->json([
2020-03-04 06:32:53 +00:00
'message' => 'Your account has been created successfully.',
2020-02-27 08:03:03 +00:00
]);
2019-05-07 11:36:21 +00:00
}
}