Support the ongoing development of Laravel.io →
Requests Input Session

I am creating a Laravel 5 store shopping cart and I would like to allow the users to compare up to 3 or 4 items. I'm not sure if my thinking is correct, but my idea is that I can have a "compare" button for each product that would fire an AJAX call to a route that would set a cookie in my controller. I could then read that cookie in another view to display the comparison. The alternative is to use a database to store the id's, but I'm not certain that is the best solution either.

Is there a better way? Also, can use an array as a cookie so that I can push/pop product ids somehow? Are there any simple examples out there to get me on the right track? I'd love to hear some suggestions to see what others are doing to handle this type of feature. Thanks!

Last updated 2 years ago.
0

Well, basically you're on the right track. But dont use cookies. store the ids in the session or on the database.. i think database is better because you can keep a history of what the customer compared.

0

Great! I appreciate the feedback. I will try sessions first and then try a database to see which is more effective for me.

0

I agree.. I would do the same DB!. So you can keep customer history and product history, even google can index it.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.