2018-08-30 13:22:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Shop\Http\Controllers;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
use Webkul\Product\Repositories\ProductRepository as Product;
|
|
|
|
|
use Webkul\Product\Repositories\ProductReviewRepository as ProductReview;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Review controller
|
|
|
|
|
*
|
|
|
|
|
* @author Jitendra Singh <jitendra@webkul.com>
|
|
|
|
|
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
|
|
|
|
|
*/
|
|
|
|
|
class ReviewController extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Contains route related configuration
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $_config;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ProductRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $product;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ProductReviewRepository object
|
|
|
|
|
*
|
|
|
|
|
* @var array
|
|
|
|
|
*/
|
|
|
|
|
protected $productReview;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new controller instance.
|
|
|
|
|
*
|
|
|
|
|
* @param Webkul\Product\Repositories\ProductRepository $product
|
|
|
|
|
* @param Webkul\Product\Repositories\ProductReviewRepository $productReview
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(Product $product, ProductReview $productReview)
|
|
|
|
|
{
|
2018-10-26 07:05:19 +00:00
|
|
|
$this->middleware('admin')->only(['update', 'destroy']);
|
2018-10-17 10:33:57 +00:00
|
|
|
|
2018-10-26 07:10:30 +00:00
|
|
|
$this->middleware('customer')->only(['create', 'store', 'destroy']);
|
2018-10-17 10:33:57 +00:00
|
|
|
|
2018-08-30 13:22:15 +00:00
|
|
|
$this->product = $product;
|
|
|
|
|
|
|
|
|
|
$this->productReview = $productReview;
|
|
|
|
|
|
|
|
|
|
$this->_config = request('_config');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Http\Response
|
2018-09-08 08:41:36 +00:00
|
|
|
*/
|
|
|
|
|
public function index()
|
2018-08-30 13:22:15 +00:00
|
|
|
{
|
2018-09-08 08:41:36 +00:00
|
|
|
return view($this->_config['view']);
|
2018-08-30 13:22:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
|
|
|
|
* @param string $slug
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function create($slug)
|
|
|
|
|
{
|
|
|
|
|
$product = $this->product->findBySlugOrFail($slug);
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'], compact('product'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
2018-09-08 08:41:36 +00:00
|
|
|
public function store(Request $request , $id)
|
2018-08-30 13:22:15 +00:00
|
|
|
{
|
|
|
|
|
$this->validate(request(), [
|
2018-09-08 08:41:36 +00:00
|
|
|
'comment' => 'required',
|
|
|
|
|
'rating' => 'required',
|
|
|
|
|
'title' => 'required',
|
2018-08-30 13:22:15 +00:00
|
|
|
]);
|
|
|
|
|
|
2018-09-08 08:41:36 +00:00
|
|
|
$data=$request->all();
|
|
|
|
|
|
|
|
|
|
$customer_id = auth()->guard('customer')->user()->id;
|
|
|
|
|
|
2018-09-21 13:43:41 +00:00
|
|
|
$data['status']='pending';
|
2018-09-08 08:41:36 +00:00
|
|
|
$data['product_id']=$id;
|
|
|
|
|
$data['customer_id']=$customer_id;
|
|
|
|
|
|
|
|
|
|
$this->productReview->create($data);
|
2018-08-30 13:22:15 +00:00
|
|
|
|
|
|
|
|
session()->flash('success', 'Review submitted successfully.');
|
|
|
|
|
|
2018-09-08 08:41:36 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display reviews accroding to product.
|
|
|
|
|
*
|
|
|
|
|
* @param string $slug
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function show($slug)
|
|
|
|
|
{
|
|
|
|
|
$product = $this->product->findBySlugOrFail($slug);
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'],compact('product'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 10:33:57 +00:00
|
|
|
/**
|
2018-09-08 08:41:36 +00:00
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit($id)
|
|
|
|
|
{
|
|
|
|
|
$review = $this->productReview->find($id);
|
|
|
|
|
|
|
|
|
|
return view($this->_config['view'],compact('review'));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-17 10:33:57 +00:00
|
|
|
/**
|
2018-09-08 08:41:36 +00:00
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
|
*/
|
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$this->productReview->update(request()->all(), $id);
|
|
|
|
|
|
|
|
|
|
session()->flash('success', 'Review updated successfully.');
|
|
|
|
|
|
2018-08-30 13:22:15 +00:00
|
|
|
return redirect()->route($this->_config['redirect']);
|
|
|
|
|
}
|
2018-10-26 07:05:19 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete the review of the current product
|
|
|
|
|
*
|
|
|
|
|
* @return response
|
|
|
|
|
*/
|
2018-10-26 07:10:30 +00:00
|
|
|
public function destroy($id) {
|
|
|
|
|
$this->productReview->delete($id);
|
2018-10-26 07:05:19 +00:00
|
|
|
|
2018-10-26 07:10:30 +00:00
|
|
|
success()->flash('success', 'Product Review Successfully Deleted');
|
|
|
|
|
|
|
|
|
|
return redirect()->back();
|
2018-10-26 07:05:19 +00:00
|
|
|
}
|
2018-08-30 13:22:15 +00:00
|
|
|
}
|