problem description
Model 1: order model, which contains all the details of each order, order number, shopping cart number.
Model 2: shopping cart data model, which contains all the information about each shopping cart, the settlement amount of the shopping cart, the waybill number, and so on.
requirements: orders are displayed in the order list in terms of shopping carts, and all the sub-order information contained in each shopping cart is displayed in the corresponding shopping cart.
since each item in the order table corresponds to an order, multiple orders can have the same shopping cart number. The shopping cart number is unique in the shopping cart information table. The relationship defined by
is as follows:
class CartsData extends Model
{
public function orders()
{
return $this->hasMany(Order::class, "cart_no", "cart_no");
}
}
class Order extends Model
{
public function cartsInfo()
{
return $this->belongsTo(CartsData::class, "cart_no", "cart_no");
}
}
excuse me: how can I write a query to get the shopping cart information and all the orders in the shopping cart when the order list is displayed according to the shopping cart? The list of orders required to be displayed can be sorted by the fields in the order information. [I don"t know if it"s clear, but I want to get the data out in the easiest way, and at the same time, I can sort or filter according to the fields in the order information table].