Advertisement
Laxtour

Untitled

Jan 9th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. namespace stock\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6.  
  7. use stock\Http\Requests;
  8. use stock\Http\Controllers\Controller;
  9. use stock\Product;
  10.  
  11. class cartController extends Controller
  12. {
  13.  
  14. public function __construct()
  15. {
  16.  
  17. if(!\Session::has('cart')) \Session::put('cart',array());
  18.  
  19. }
  20.  
  21. // Show cart
  22.  
  23. public function show()
  24. {
  25. $cart = \Session::get('cart');
  26.  
  27. return view('store.cart',compact('cart'));
  28. }
  29.  
  30. // Add item
  31.  
  32. public function add(Product $product)
  33. {
  34. $cart = \Session::get('cart');
  35. $product->quantity = 1;
  36. $cart[$product->slug] = $product;
  37. \Session::put('cart',$cart);
  38.  
  39. return redirect()->route('cart-show');
  40.  
  41. }
  42.  
  43. // Delete Item
  44.  
  45. public function delete(Product $product)
  46. {
  47. $cart= \Session::get('cart');
  48. unset($cart[$product->slug]);
  49. \Session::put('cart',$cart);
  50. return redirect()->route('cart-show');
  51. }
  52.  
  53. // Update item
  54. public function update(Product $product,$quantity)
  55. {
  56. $cart= \Session::get('cart');
  57. $cart[$product->slug]->quantity=$quantity;
  58. \Session::put('cart',$cart);
  59. return redirect()->route('cart-show');
  60. }
  61.  
  62. // Trash item
  63. public function trash()
  64. {
  65. \Session::forget('cart');
  66. return redirect()->route('home');
  67.  
  68. }
  69. // Total
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement