sarga/packages/Webkul/Customer/src/Http/Controllers/CustomerController.php

180 lines
4.5 KiB
PHP
Raw Normal View History

<?php
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Customer\Repositories\CustomerRepository;
2018-09-21 13:43:41 +00:00
use Webkul\Product\Repositories\ProductReviewRepository as ProductReview;
2018-07-27 13:37:56 +00:00
use Webkul\Customer\Models\Customer;
use Auth;
/**
2018-10-17 10:33:57 +00:00
* Customer controlller for the customer basically for the tasks of customers which will be done after customer authentication.
*
* @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;
/**
* CustomerRepository object
*
* @var array
*/
protected $customer;
2018-09-21 13:43:41 +00:00
/**
* ProductReviewRepository object
*
* @var array
*/
protected $productReview;
/**
2018-10-17 10:33:57 +00:00
* Create a new Repository instance.
2018-09-21 13:43:41 +00:00
*
* @param Webkul\Customer\Repositories\CustomerRepository $customer
* @param Webkul\Product\Repositories\ProductReviewRepository $productReview
2018-09-21 13:43:41 +00:00
* @return void
*/
public function __construct(
CustomerRepository $customer,
ProductReview $productReview
)
{
$this->middleware('customer');
$this->_config = request('_config');
$this->customer = $customer;
2018-09-21 13:43:41 +00:00
$this->productReview = $productReview;
}
/**
2018-10-17 10:33:57 +00:00
* 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'));
2018-07-27 13:37:56 +00:00
}
/**
2018-10-17 10:33:57 +00:00
* 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'));
}
/**
2018-10-17 10:33:57 +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',
'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');
return redirect()->back();
} else {
Session()->flash('success','Profile Updated Successfully');
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');
return redirect()->back();
} else {
Session()->flash('success','Profile Updated Successfully');
return redirect()->back();
}
}
}
2018-10-17 10:33:57 +00:00
/**
* Load the view for the customer account panel, showing orders in a table.
*
* @return Mixed
*/
public function orders()
{
return view($this->_config['view']);
}
2018-10-17 10:33:57 +00:00
/**
* Load the view for the customer account panel, showing wishlist items.
*
* @return Mixed
*/
public function wishlist()
{
return view($this->_config['view']);
}
2018-10-17 10:33:57 +00:00
/**
* Load the view for the customer account panel, showing approved reviews.
*
* @return Mixed
*/
public function reviews()
{
2018-10-17 10:33:57 +00:00
$reviews = $this->productReview->getCustomerReview();
2018-09-21 13:43:41 +00:00
return view($this->_config['view'], compact('reviews'));
}
2018-10-17 10:33:57 +00:00
/**
* Load the view for the customer account panel, shows the customer address.
*
* @return Mixed
*/
public function address()
{
return view($this->_config['view']);
}
}