亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php laravel 中的會話會隨著每次使用而不斷重置

php laravel 中的會話會隨著每次使用而不斷重置

PHP
米琪卡哇伊 2022-07-09 11:01:15
大家好,當我嘗試將它們用于購物車時,我對 php 中的會話有疑問我用下面的代碼解釋class Cart {     public $items;     public $totalQty=0;     public $totalPrice=0;     public function __construct($oldcart)   {    if ($oldcart){        $this->items=$oldcart->items;        $this->totalQty=$oldcart->totalQty;        $this->totalPrice=$oldcart->totalPrice;    }}public function add($item , $id){    $storeditem=['qty'=>0,'price'=>$item->price,'item'=>$item];    if ($this->items) {        if (array_key_exists($id, $this->items)) {            $storeditem = $this->items[$id];        }}    $storeditem['qty']++;    $storeditem['price']=$item->price*$storeditem['qty'];    $this->items[$id]=$storeditem;    $this->totalQty++;    $this->totalPrice+=$item->price;}}這是將商品添加到 shopping_cart 的簡單類我像這樣使用它public function getAddToCart(Request $request, $id)    {        //        $product=Product::find($id);        $oldcart=Session::has('Shopcart')? Session::get('Shopcart'): null;        $cart=new Cart($oldcart);        $cart->add($product,$product->id);        $request->session()->put('Shopcart', $cart);        return redirect()->route('shop.index');    }有了這兩部分,我可以將項目添加到會話中<span id="cart-total">{{ Session::has('Shopcart')?  Session::get('Shopcart')->totalQty : ''}}</span>我在這里看不到任何東西是什么問題我看不到我還在控制器中添加了 Session 類并且路由也可以
查看完整描述

1 回答

?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

我找到了@apokryfos 幫助的答案二人組,5.2 以上的 laravel 的默認驅動程序是 cookie 我需要的只是將其更改為文件以執行技巧二人組我不知道如何設置這樣的 cookie 如果你找到一些關于此的文檔請分享與我一起



查看完整回答
反對 回復 2022-07-09
  • 1 回答
  • 0 關注
  • 112 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號