【问题标题】:Laravel Session LimitLaravel 会话限制
【发布时间】:2018-09-03 22:20:41
【问题描述】:

如何获得有限制的会话项目?

我的购物车在会话中存储物品,我只想显示添加到会话中的最新 2 件物品,我该怎么做?

我在作曲家视图中使用它,这是我的代码

//cart products
      View::composer('*', function ($view) {
        $user = Auth()->user();
        if (!Session::has('cart')) {
          return view('frontend.cart');
        }
        $oldCart = Session::get('cart');
        $cart = new Cart($oldCart);
        $total = $cart->totalPrice;
        $view->with('products', $cart->items, 'totalPrice', $cart->totalPrice, 'user', $user, 'total', $total);
      });

【问题讨论】:

    标签: laravel session


    【解决方案1】:

    您可以使用put 来做到这一点:

    Session::put('sess_cart', $request->input('cart'));
    

    【讨论】:

      猜你喜欢
      • 2017-04-26
      • 2020-05-04
      • 2014-08-16
      • 2011-10-11
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2012-07-27
      相关资源
      最近更新 更多