Merge pull request #4006 from devansh-webkul/review_api_issue

Fixed no validation error message are shown on submitting review without required params via API #3977
This commit is contained in:
Jitendra Singh 2020-10-07 12:31:54 +05:30 committed by GitHub
commit 2153820700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 9 deletions

View File

@ -9,21 +9,21 @@ use Webkul\API\Http\Resources\Catalog\ProductReview as ProductReviewResource;
class ReviewController extends Controller
{
/**
* Contains current guard
* Contains current guard.
*
* @var array
*/
protected $guard;
/**
* ProductReviewRepository object
* ProductReviewRepository $reviewRepository
*
* @var \Webkul\Product\Repositories\ProductReviewRepository
*/
protected $reviewRepository;
/**
* Controller instance
* Controller instance.
*
* @param Webkul\Product\Repositories\ProductReviewRepository $reviewRepository
*/
@ -47,24 +47,25 @@ class ReviewController extends Controller
{
$customer = auth($this->guard)->user();
$this->validate(request(), [
$this->validate($request, [
'comment' => 'required',
'rating' => 'required|numeric|min:1|max:5',
'title' => 'required',
]);
$data = array_merge(request()->all(), [
$productReview = $this->reviewRepository->create([
'customer_id' => $customer ? $customer->id : null,
'name' => $customer ? $customer->name : request()->input('name'),
'name' => $customer ? $customer->name : $request->get('name'),
'status' => 'pending',
'product_id' => $id,
'comment' => $request->comment,
'rating' => $request->rating,
'title' => $request->title
]);
$productReview = $this->reviewRepository->create($data);
return response()->json([
'message' => 'Your review submitted successfully.',
'data' => new ProductReviewResource($this->reviewRepository->find($productReview->id)),
'data' => new ProductReviewResource($productReview),
]);
}
}