【问题标题】:dynamic transportation value in cart app laravel购物车应用程序 laravel 中的动态运输价值
【发布时间】:2021-12-30 11:13:34
【问题描述】:

我想从card.php中的数据库中获取运输成本,但现在它静态写入25000。这个成本必须是动态的,网站所有者可以更改它。

在照片传输中静态写入 但我想从数据库调用并且是动态的

public function __construct($oldCart)

{
    if($oldCart){
        $this->items = $oldCart->items;
        $this->totalQty = $oldCart->totalQty;
        $this->totalPrice = $oldCart->totalPrice;
        $this->totalPurePrice = $oldCart->totalPurePrice;
        $this->totalDiscountPrice = $oldCart->totalDiscountPrice;
        $this->transportation = $oldCart->transportation;

    }
}

}

【问题讨论】:

    标签: mysql laravel shopping-cart


    【解决方案1】:

    在您将照片放在上面的代码之后执行此操作。您不需要__construct。你应该有这样的getter和setter:

    public function setTransportation($value)
        {
            $this->transportation= $value;
        }
    
        public function getTransportation()
        {
            return $this->transportation;
        }
    

    在另一种方法中设置一个值(例如:5),您可以从数据库中给它:

    $this->setTransportation(5);
    

    那就这样弄吧:

    $myTransportation=$this->getTransportation();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 2019-12-30
      • 1970-01-01
      • 2013-08-30
      • 2017-02-08
      • 1970-01-01
      • 2019-10-04
      相关资源
      最近更新 更多