Ask for help: [Laravel] questions about one-to-many associative queries in Eloquent

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].

Apr.28,2021

try
$cart->orders()->whereOrderNo("1")->get();
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb6106-4836c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb6106-4836c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?