ReviewController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Http\Controllers\Seller;
  3. use Illuminate\Http\Request;
  4. use App\Models\Review;
  5. use Auth;
  6. use DB;
  7. class ReviewController extends Controller
  8. {
  9. public function index(Request $request)
  10. {
  11. $reviews = DB::table('reviews')
  12. ->orderBy('id', 'desc')
  13. ->join('products', 'reviews.product_id', '=', 'products.id')
  14. ->where('products.user_id', Auth::user()->id)
  15. ->select('reviews.id')
  16. ->distinct()
  17. ->paginate(9);
  18. foreach ($reviews as $key => $value) {
  19. $review = \App\Models\Review::find($value->id);
  20. $review->viewed = 1;
  21. $review->save();
  22. }
  23. return view('seller.reviews', compact('reviews'));
  24. }
  25. public function edit(Request $request)
  26. {
  27. $reviews =\App\Models\Review::find($request->id);
  28. $lang = $request->lang;
  29. return view('seller.edit', compact('reviews', 'lang'));
  30. }
  31. public function update(Request $request)
  32. {
  33. $review = Review::findOrFail($request->id);
  34. $review->comment = $request->comment;
  35. $review->rating = $request->rating;
  36. $review->save();
  37. flash(translate('Edit successfully!'))->success();
  38. return back();
  39. }
  40. public function updateStatus(Request $request)
  41. {
  42. $review = Review::findOrFail($request->id);
  43. $review->status = $request->status;
  44. $review->save();
  45. return 1;
  46. }
  47. }