WishlistController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Auth;
  5. use App\Models\Wishlist;
  6. use App\Models\Category;
  7. class WishlistController extends Controller
  8. {
  9. /**
  10. * Display a listing of the resource.
  11. *
  12. * @return \Illuminate\Http\Response
  13. */
  14. public function index()
  15. {
  16. $wishlists = Wishlist::where('user_id', Auth::user()->id)->paginate(9);
  17. return view('frontend.user.view_wishlist', compact('wishlists'));
  18. }
  19. /**
  20. * Show the form for creating a new resource.
  21. *
  22. * @return \Illuminate\Http\Response
  23. */
  24. public function create()
  25. {
  26. //
  27. }
  28. /**
  29. * Store a newly created resource in storage.
  30. *
  31. * @param \Illuminate\Http\Request $request
  32. * @return \Illuminate\Http\Response
  33. */
  34. public function store(Request $request)
  35. {
  36. if(Auth::check()){
  37. $wishlist = Wishlist::where('user_id', Auth::user()->id)->where('product_id', $request->id)->first();
  38. if($wishlist == null){
  39. $wishlist = new Wishlist;
  40. $wishlist->user_id = Auth::user()->id;
  41. $wishlist->product_id = $request->id;
  42. $wishlist->save();
  43. }
  44. return view('frontend.partials.wishlist');
  45. }
  46. return 0;
  47. }
  48. public function remove(Request $request)
  49. {
  50. $wishlist = Wishlist::findOrFail($request->id);
  51. if($wishlist!=null){
  52. if(Wishlist::destroy($request->id)){
  53. return view('frontend.partials.wishlist');
  54. }
  55. }
  56. }
  57. /**
  58. * Display the specified resource.
  59. *
  60. * @param int $id
  61. * @return \Illuminate\Http\Response
  62. */
  63. public function show($id)
  64. {
  65. //
  66. }
  67. /**
  68. * Show the form for editing the specified resource.
  69. *
  70. * @param int $id
  71. * @return \Illuminate\Http\Response
  72. */
  73. public function edit($id)
  74. {
  75. //
  76. }
  77. /**
  78. * Update the specified resource in storage.
  79. *
  80. * @param \Illuminate\Http\Request $request
  81. * @param int $id
  82. * @return \Illuminate\Http\Response
  83. */
  84. public function update(Request $request, $id)
  85. {
  86. //
  87. }
  88. /**
  89. * Remove the specified resource from storage.
  90. *
  91. * @param int $id
  92. * @return \Illuminate\Http\Response
  93. */
  94. public function destroy($id)
  95. {
  96. //
  97. }
  98. }