Answer the question
In order to leave comments, you need to log in
Laravel. How to build relationships in a database?
Good afternoon!
Help deal with the issue.
There is a user's personal account (hereinafter referred to as LKP), it contains goods. I implemented this: the product belongs to the paintwork.
There are product formats, 3 types: for men, for women and for children. I have created a table in db with these formats.
1 column - id;
2nd column - format name.
Now you need to create a table (I created it, but maybe you can tell me what I did wrong) with the goods that the user ordered.
It looks like this:
1) id LKP.
2) item id.
3) format id.
Everything seems to be correct, but now I can not understand how to build relationships with this table.
Now the task is as follows: goods with a certain format are bought in the personal account and a basket with the selected goods should be displayed on the side. But so far I can’t figure out how to get through this jungle of relationships and get the necessary data, for example, display the format name next to the product name and product photo. Please tell me how to implement.
Here's what I have now:
LCP
public function photos()
{
return $this->hasMany(CartPhoto::class);
}
public function order()
{
return $this->hasMany(Order::class);
}
public function cart()
{
return $this->belongsTo(PersonalCart::class);
}
public function order()
{
return $this->belongsTo(Order::class);
}
public function order()
{
return $this->belongsTo(Order::class);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question