Answer the question
In order to leave comments, you need to log in
What is the best way to implement a database and work with it for a "basket of goods" on Eloquent Laravel?
Hello, I need to do something like a "cart of goods". Please help with advice. There are tables:
users
id - integer
email - string
profile
id - integer
user_id - integer (внешний ключ к users)
name - string
products
id - integer
description - string
korzina
id - integer
kolichestvo - integer
products_id - integer (внешний ключ к products)
user_id - integer (внешний ключ к users)
Answer the question
In order to leave comments, you need to log in
How is a profile different from a user?
Should the cart be linked to a user or a profile?
Can one person have several baskets and the functionality of switching between them?
There is a hypothesis that "translation" is a better fit than "transliteration". Visually cart is better than korzina.
Depending on the answers above, there may be nuances, but the main ideas are:
- The cart is a basic entity. If the connection with the owner is 1-1, then the key can be duplicated. It is not bad to store general information in it - the total amount, weight
- Products are tied to the basket in a separate table, or inside the json field / serialization for reliability. json is my favorite.
- It's nice to store timestamps near the basket
- I would store baskets not in the same mysql database. Either a cache or another DB (like mongoDb), but I'm not sure if this advice is relevant "for a beginner".
- there is a theory that the basket is an order in the "not completed" state. If you follow it, then you should look at it from the point of view of the corresponding architecture. The ideas above do not take this into account.
A table is not needed at all for the basket, unless it is necessary, for example, to spam it later with the letter "you chose something, but did not make an order."
A session or, in extreme cases, a cookie is quite enough, especially for some primitive implementation without a "full-fledged" store.
I propose another option, here you have a korzina table and a products_id cell, so you are tormented with this, it was easier to serialize the basket when ordering so that you can work more conveniently later. Yes, it may not be entirely clear, but believe me, it's worth it, if you write something, I'll explain or even show the source code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question