【问题标题】:update session array value in laravel在 laravel 中更新会话数组值
【发布时间】:2020-06-06 16:30:51
【问题描述】:

我在 laravel 中创建了一个购物车页面,现在我想在 laravel 中添加折扣代码部分,以便每个折扣代码减去购物车页面中每个产品的价格。

我的任何产品的购物车会话保存在这样的会话中:


// product with id 1
  "cart_1" => [
    "id" => "1"
    "product" => "accounting"
    "quantity" => 5
    "price" => 50000
    "attr" => [
    // product options that some user choose this
      "torfehnegar_evidence" => "true"
    ]
  ]

// product with id 3
  "cart_3" => [
    "id" => "3"
    "product" => "programming"
    "quantity" => 2
    "price" => 600
    "attr" =>  [
      // product options that some user choose this
        ]
  ]

现在,当用户插入价格为 500 的折扣代码时,我希望这个数组像这样更改


// product with id 1
  "cart_1" => [
    "id" => "1"
    "product" => "accounting"
    "quantity" => 5
    "price" => 49500 // the main price minus from discount price
    "attr" => [
    // product options
      "torfehnegar_evidence" => "true"
    ]
  ]

// product with id 3
  "cart_3" => [
    "id" => "3"
    "product" => "programming"
    "quantity" => 2
    "price" => 100 // the main price minus from discount price
    "attr" =>  [
      // product options
        ]
  ]

此更改必须替换 laravel 中的同一会话

【问题讨论】:

  • 到目前为止,您为实现目标做了哪些尝试?

标签: php arrays laravel


【解决方案1】:

您可能希望为此实现一个服务容器。这个视频告诉你如何Youtube

【讨论】:

    猜你喜欢
    • 2020-03-25
    • 2017-06-10
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 2017-01-07
    相关资源
    最近更新 更多