Reputation: 93
I have a view with a foreach, here I have following code:
@foreach($shopGSM as $shopGSM)
<th colspan="3"><h4>{{ $shopGSM->name }}</h4></th>
<td id="order"><a href="{{ route('eindwerk.shoppingcart', ['id' => $shopGSM->category_id]) }}"><button class="btn btn-primary">+ Add to cart</button></a></td>
@endforeach
My question here is how do I make a cookie to see what products my user has clicked? Really new to this, so I'am happy if anyone can help me?
Upvotes: 1
Views: 3360
Reputation: 33058
In your controller's method (or closure) that responds to the route eindwerk.shoppingcart
when that link is clicked, you would add code there to create the cookie and then return it with your next view.
You can check the docs here to see how to do just that... https://laravel.com/docs/5.2/requests#cookies
I would recommend doing a little more research because usually cookies are not the way to go for this. If you want to store the cart on a session by session basis, then you can use the session. If you want to store the cart per user and require a login, then you'd store everything in the database. There should be some pretty good cart tutorials out there specifically for Laravel to get you started.
Upvotes: 1