* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ class CustomerController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ protected $_config; /** * CustomerRepository object * * @var array */ protected $customer; /** * ProductReviewRepository object * * @var array */ protected $productReview; /** * Create a new Repository instance. * * @param Webkul\Customer\Repositories\CustomerRepository $customer * @param Webkul\Product\Repositories\ProductReviewRepository $productReview * @return void */ public function __construct( CustomerRepository $customer, ProductReview $productReview ) { $this->middleware('customer'); $this->_config = request('_config'); $this->customer = $customer; $this->productReview = $productReview; } /** * Taking the customer to profile details page * * @return View */ public function index() { $customer = $this->customer->find(auth()->guard('customer')->user()->id); return view($this->_config['view'], compact('customer')); } /** * For loading the edit form page. * * @return View */ public function editIndex() { $customer = $this->customer->find(auth()->guard('customer')->user()->id); return view($this->_config['view'], compact('customer')); } /** * Edit function for editing customer profile. * * @return Redirect. */ public function edit() { $id = auth()->guard('customer')->user()->id; $this->validate(request(), [ 'first_name' => 'string', 'last_name' => 'string', 'gender' => 'required', 'date_of_birth' => 'date|before:today', 'email' => 'email|unique:customers,email,'.$id, 'password' => 'confirmed' ]); $data = collect(request()->input())->except('_token')->toArray(); if($data['date_of_birth'] == "") { unset($data['date_of_birth']); } if($data['oldpassword'] == null) { $data = collect(request()->input())->except(['_token','password','password_confirmation','oldpassword'])->toArray(); if($data['date_of_birth'] == "") { unset($data['date_of_birth']); } if($this->customer->update($data, $id)) { Session()->flash('success', trans('shop::app.customer.account.profile.edit-success')); return redirect()->back(); } else { Session()->flash('success', trans('shop::app.customer.account.profile.edit-fail')); return redirect()->back(); } } else { if(Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) { $data = collect(request()->input())->except(['_token','oldpassword'])->toArray(); $data['password'] = bcrypt($data['password']); if($data['date_of_birth'] == "") { unset($data['date_of_birth']); } } else { session()->flash('warning', trans('shop::app.customer.account.profile.unmatch')); return redirect()->back(); } if($this->customer->update($data, $id)) { Session()->flash('success', trans('shop::app.customer.account.profile.edit-success')); return redirect()->back(); } else { Session()->flash('success', trans('shop::app.customer.account.profile.edit-fail')); return redirect()->back(); } } } /** * Load the view for the customer account panel, showing orders in a table. * * @return Mixed */ public function orders() { return view($this->_config['view']); } /** * Load the view for the customer account panel, showing wishlist items. * * @return Mixed */ public function wishlist() { return view($this->_config['view']); } /** * Load the view for the customer account panel, showing approved reviews. * * @return Mixed */ public function reviews() { $reviews = $this->productReview->getCustomerReview(); return view($this->_config['view'], compact('reviews')); } /** * Load the view for the customer account panel, shows the customer address. * * @return Mixed */ public function address() { return view($this->_config['view']); } }