拉拉维尔:从称为的关系中找回其他关系

发布于 2025-02-02 18:12:16 字数 3918 浏览 1 评论 0原文

因此,我有这个我一直在转换toarray的集合,这是我的集合:

 array:1 [▼
  0 => array:14 [▼
    "id" => 1
    "timeout" => "2022-05-29 15:15:34"
    "address" => "Awikwok"
    "regency" => "["Kotawaringin Barat"]"
    "province" => "["Jawa Tengah"]"
    "total" => 68000
    "shipping_cost" => 18000
    "sub_total" => 50000
    "user_id" => 1
    "proof_of_payment" => null
    "status" => "PENDING"
    "created_at" => "2022-05-28T15:15:34.000000Z"
    "updated_at" => "2022-05-28T15:15:34.000000Z"
    "user" => array:7 [▼
      "id" => 1
      "name" => "user"
      "email" => "[email protected]"
      "email_verified_at" => null
      "created_at" => "2022-05-28T15:12:21.000000Z"
      "updated_at" => "2022-05-28T15:12:21.000000Z"
      "carts" => array:2 [▼
        0 => array:7 [▼
          "id" => 1
          "user_id" => 1
          "product_id" => 2
          "qty" => 1
          "created_at" => "2022-05-28T15:12:39.000000Z"
          "updated_at" => "2022-05-28T15:12:39.000000Z"
          "products" => array:10 [▼
            "id" => 2
            "product_name" => "Hitam baju"
            "price" => 50000
            "description" => "kjeqwoejwqpoewq"
            "product_rate" => "0"
            "stock" => "5"
            "weight" => "4"
            "deleted_at" => null
            "created_at" => "2022-05-28T15:11:54.000000Z"
            "updated_at" => "2022-05-28T15:11:54.000000Z"
          ]
        ]
        1 => array:7 [▶]
      ]
    ]
  ]
]

在这种情况下,我想从事务表中显示产品属性,但是这是我的代码:

 @foreach ($transactionByUser->user->carts as $item)
                        <div class="col-lg-3 m-0">

                            <h6> <b>Product name </b> <br> </h6>
                            <h6> <b>Price </b> <br> </h6>
                            <h6> <b>Qty </b> <br> </h6>
                            <h6> <b>Shipping Cost </b> <br> </h6>
                            <h6> <b>Sub total </b></h6>
                            <h6> <b> &nbsp; </b></h6>
                            <br>
                            <h6> <b> Total </b></h6>

                        </div>
                        <div class="col-lg-3 text-end m-0">
                            <h6>{{ $item->products['product_name'] }}</h6>
                            <h6>Rp.{{ number_format($item->products->price) }}</h6>
                            <h6>{{ $item->qty }} item</h6>
                            <h6>Rp. {{ number_format($transactionByUser->shipping_cost) }}</h6>
                            <h6>{{ $item->qty }} item * Rp.{{ number_format($item->products->price) }} = </h6>
                            <h6>Rp.{{ number_format($transactionByUser->sub_total) }}</h6>
                            <hr>
                            <h6>Rp.{{ number_format($transactionByUser->total) }}</h6>
                        </div>
                        <div class="col-lg-6 d-flex justify-content-center">
                            @foreach ($item->products->images as $image)
                                <img class="img-thumbnail h-75" src="{{ asset('images/' . $image->image_name) }}" alt="">
                            @endforeach
                        </div>
                        <hr>
                    @endforeach

问题是,当我这样渲染时,它是检索我要显示的所有当前产品,如何修复它?

So, i have this collection that i've been convert toArray , this is my collection :

 array:1 [▼
  0 => array:14 [▼
    "id" => 1
    "timeout" => "2022-05-29 15:15:34"
    "address" => "Awikwok"
    "regency" => "["Kotawaringin Barat"]"
    "province" => "["Jawa Tengah"]"
    "total" => 68000
    "shipping_cost" => 18000
    "sub_total" => 50000
    "user_id" => 1
    "proof_of_payment" => null
    "status" => "PENDING"
    "created_at" => "2022-05-28T15:15:34.000000Z"
    "updated_at" => "2022-05-28T15:15:34.000000Z"
    "user" => array:7 [▼
      "id" => 1
      "name" => "user"
      "email" => "[email protected]"
      "email_verified_at" => null
      "created_at" => "2022-05-28T15:12:21.000000Z"
      "updated_at" => "2022-05-28T15:12:21.000000Z"
      "carts" => array:2 [▼
        0 => array:7 [▼
          "id" => 1
          "user_id" => 1
          "product_id" => 2
          "qty" => 1
          "created_at" => "2022-05-28T15:12:39.000000Z"
          "updated_at" => "2022-05-28T15:12:39.000000Z"
          "products" => array:10 [▼
            "id" => 2
            "product_name" => "Hitam baju"
            "price" => 50000
            "description" => "kjeqwoejwqpoewq"
            "product_rate" => "0"
            "stock" => "5"
            "weight" => "4"
            "deleted_at" => null
            "created_at" => "2022-05-28T15:11:54.000000Z"
            "updated_at" => "2022-05-28T15:11:54.000000Z"
          ]
        ]
        1 => array:7 [▶]
      ]
    ]
  ]
]

in this case, i want to show product attribute from transaction table , but here's my code :

 @foreach ($transactionByUser->user->carts as $item)
                        <div class="col-lg-3 m-0">

                            <h6> <b>Product name </b> <br> </h6>
                            <h6> <b>Price </b> <br> </h6>
                            <h6> <b>Qty </b> <br> </h6>
                            <h6> <b>Shipping Cost </b> <br> </h6>
                            <h6> <b>Sub total </b></h6>
                            <h6> <b>   </b></h6>
                            <br>
                            <h6> <b> Total </b></h6>

                        </div>
                        <div class="col-lg-3 text-end m-0">
                            <h6>{{ $item->products['product_name'] }}</h6>
                            <h6>Rp.{{ number_format($item->products->price) }}</h6>
                            <h6>{{ $item->qty }} item</h6>
                            <h6>Rp. {{ number_format($transactionByUser->shipping_cost) }}</h6>
                            <h6>{{ $item->qty }} item * Rp.{{ number_format($item->products->price) }} = </h6>
                            <h6>Rp.{{ number_format($transactionByUser->sub_total) }}</h6>
                            <hr>
                            <h6>Rp.{{ number_format($transactionByUser->total) }}</h6>
                        </div>
                        <div class="col-lg-6 d-flex justify-content-center">
                            @foreach ($item->products->images as $image)
                                <img class="img-thumbnail h-75" src="{{ asset('images/' . $image->image_name) }}" alt="">
                            @endforeach
                        </div>
                        <hr>
                    @endforeach

the problem is, when i do render like that, it's retrieving all product instead current product that i want to show it, how to fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文