ProductQueryController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\Product;
  4. use App\Models\ProductQuery;
  5. use Auth;
  6. use Illuminate\Http\Request;
  7. class ProductQueryController extends Controller
  8. {
  9. /**
  10. * Retrieve queries that belongs to current seller
  11. */
  12. public function index()
  13. {
  14. $queries = ProductQuery::where('seller_id', Auth::id())->latest()->paginate(20);
  15. return view('backend.support.product_query.index', compact('queries'));
  16. }
  17. /**
  18. * Retrieve specific query using query id.
  19. */
  20. public function show($id)
  21. {
  22. $query = ProductQuery::find(decrypt($id));
  23. return view('backend.support.product_query.show', compact('query'));
  24. }
  25. /**
  26. * store products queries through the ProductQuery model
  27. * data comes from product details page
  28. * authenticated user can leave queries about the product
  29. */
  30. public function store(Request $request)
  31. {
  32. $this->validate($request, [
  33. 'question' => 'required|string',
  34. ]);
  35. $product = Product::find($request->product);
  36. $query = new ProductQuery();
  37. $query->customer_id = Auth::id();
  38. $query->seller_id = $product->user_id;
  39. $query->product_id = $product->id;
  40. $query->question = $request->question;
  41. $query->save();
  42. flash(translate('Your query has been submittes successfully'))->success();
  43. return redirect()->back();
  44. }
  45. /**
  46. * Store reply against the question from Admin panel
  47. */
  48. public function reply(Request $request, $id)
  49. {
  50. $this->validate($request, [
  51. 'reply' => 'required',
  52. ]);
  53. $query = ProductQuery::find($id);
  54. $query->reply = $request->reply;
  55. $query->save();
  56. flash(translate('Replied successfully!'))->success();
  57. return redirect()->route('product_query.index');
  58. }
  59. }