-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathReviewController.php
More file actions
37 lines (31 loc) · 1.12 KB
/
ReviewController.php
File metadata and controls
37 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
namespace App\Http\Controllers\Store;
use App\Http\Controllers\Controller;
use App\Models\ProductReview;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ReviewController extends Controller
{
public function store(Request $request)
{
$request->validate([
'product_id' => 'required|exists:products,id',
'rating' => 'required|integer|min:1|max:5',
'review' => 'nullable|string|max:500',
]);
// Check if already reviewed
if (ProductReview::where('product_id', $request->product_id)
->where('customer_id', Auth::guard('customer')->id())
->exists()) {
return back()->with('error', __('store.product_detail.review_already_submitted'));
}
ProductReview::create([
'customer_id' => Auth::guard('customer')->id(),
'product_id' => $request->product_id,
'rating' => $request->rating,
'review' => $request->review,
'is_approved' => 1,
]);
return back()->with('success', __('store.product_detail.review_success'));
}
}