2018-07-20 15:07:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Customer\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
2018-08-23 13:11:56 +00:00
|
|
|
use Webkul\Customer\Repositories\CustomerRepository;
|
2018-07-27 13:37:56 +00:00
|
|
|
use Webkul\Customer\Models\Customer;
|
2018-08-23 13:11:56 +00:00
|
|
|
use Auth;
|
2018-07-20 15:07:16 +00:00
|
|
|
|
|
|
|
|
/**
|
2018-07-24 14:33:49 +00:00
|
|
|
* Customer controlller for the customer
|
|
|
|
|
* basically for the tasks of customers
|
|
|
|
|
* which will be done after customer
|
|
|
|
|
* authenticastion.
|
2018-07-20 15:07:16 +00:00
|
|
|
*
|
|
|
|
|
* @author Prashant Singh <prashant.singh852@webkul.com>
|
|
|
|
|
* @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;
|
2018-08-23 13:11:56 +00:00
|
|
|
protected $customer;
|
2018-07-20 15:07:16 +00:00
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
|
|
|
|
|
public function __construct(CustomerRepository $customer)
|
2018-07-20 15:07:16 +00:00
|
|
|
{
|
|
|
|
|
$this->_config = request('_config');
|
2018-08-23 13:11:56 +00:00
|
|
|
$this->customer = $customer;
|
|
|
|
|
$this->middleware('auth:customer');
|
2018-07-20 15:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2018-07-24 14:33:49 +00:00
|
|
|
/**
|
|
|
|
|
* For taking the customer
|
|
|
|
|
* to the dashboard after
|
|
|
|
|
* authentication
|
|
|
|
|
* @return view
|
|
|
|
|
*/
|
2018-08-23 13:11:56 +00:00
|
|
|
private function getCustomer($id) {
|
|
|
|
|
$customer = collect($this->customer->findOneWhere(['id'=>$id]));
|
2018-07-27 13:37:56 +00:00
|
|
|
return $customer;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
/**
|
|
|
|
|
* Taking the customer
|
|
|
|
|
* to profile details
|
|
|
|
|
* page
|
|
|
|
|
* @return View
|
|
|
|
|
*/
|
|
|
|
|
public function index() {
|
2018-07-27 13:37:56 +00:00
|
|
|
$id = auth()->guard('customer')->user()->id;
|
2018-08-23 13:11:56 +00:00
|
|
|
|
2018-07-27 13:37:56 +00:00
|
|
|
$customer = $this->getCustomer($id);
|
2018-08-23 13:11:56 +00:00
|
|
|
|
2018-07-27 13:37:56 +00:00
|
|
|
return view($this->_config['view'])->with('customer', $customer);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
/**
|
|
|
|
|
* For loading the
|
|
|
|
|
* edit form page.
|
|
|
|
|
*
|
|
|
|
|
* @return View
|
|
|
|
|
*/
|
|
|
|
|
public function editIndex() {
|
2018-07-27 13:37:56 +00:00
|
|
|
$id = auth()->guard('customer')->user()->id;
|
2018-08-23 13:11:56 +00:00
|
|
|
|
2018-07-27 13:37:56 +00:00
|
|
|
$customer = $this->getCustomer($id);
|
2018-08-23 13:11:56 +00:00
|
|
|
|
2018-07-27 13:37:56 +00:00
|
|
|
return view($this->_config['view'])->with('customer', $customer);
|
2018-07-20 15:07:16 +00:00
|
|
|
}
|
2018-08-23 13:11:56 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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',
|
|
|
|
|
'phone' => 'string|size:10',
|
|
|
|
|
'email' => 'email|unique:customers,email,'.$id,
|
|
|
|
|
'password' => 'confirmed|required_if:oldpassword,!=,null'
|
|
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$data = collect(request()->input())->except('_token')->toArray();
|
|
|
|
|
|
|
|
|
|
if($data['oldpassword'] == null) {
|
|
|
|
|
|
|
|
|
|
$data = collect(request()->input())->except(['_token','password','password_confirmation','oldpassword'])->toArray();
|
|
|
|
|
if($this->customer->update($data, $id)) {
|
|
|
|
|
Session()->flash('success','Profile Updated Successfully');
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
} else {
|
|
|
|
|
Session()->flash('success','Profile Updated Successfully');
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
$data = collect(request()->input())->except(['_token','oldpassword'])->toArray();
|
|
|
|
|
|
|
|
|
|
$data['password'] = bcrypt($data['password']);
|
|
|
|
|
|
|
|
|
|
if($this->customer->update($data, $id)) {
|
|
|
|
|
Session()->flash('success','Profile Updated Successfully');
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
} else {
|
|
|
|
|
Session()->flash('success','Profile Updated Successfully');
|
2018-08-24 05:18:53 +00:00
|
|
|
|
2018-08-23 13:11:56 +00:00
|
|
|
return redirect()->back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function orders() {
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function wishlist() {
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function reviews() {
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function address() {
|
|
|
|
|
return view($this->_config['view']);
|
|
|
|
|
}
|
2018-07-20 15:07:16 +00:00
|
|
|
}
|