久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel 在會話中存儲數組

Laravel Store Array in Session(Laravel 在會話中存儲數組)
本文介紹了Laravel 在會話中存儲數組的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在會話中存儲數組時遇到問題.我正在制作購物車,但它似乎不起作用.

I have been having trouble storing an array in session. I am making a shopping cart and it doesn't seem to work.

public function __construct(){

  $product = array(1,2,3,4);
  Session::push('cart', $product);

}

然后像這樣在視圖中檢索它.

and then retrieve it in the view like this.

{{Session::get('cart')}}

但是我一直收到這樣的錯誤.

However I keep getting an error like this.

htmlentities() expects parameter 1 to be string, array given

有關如何創建可存儲一系列商品的購物車的任何線索和建議.

Any clues and advice on how to create a shopping cart that stores an array of items.

推薦答案

如果你需要使用 session 中的數組作為字符串,你需要像這樣使用 Collection:

If you need to use the array from session as a string, you need to use Collection like this:

$product = collect([1,2,3,4]);
Session::push('cart', $product);

當您在 html 中使用 {{Session::get('cart');}} 時,這將使它起作用.請注意 Session::push 因為它會在會話中始終附加新產品.您應該使用 Session::put 以確保產品將始終更新.

This will make it work when you will be using {{Session::get('cart');}} in your htmls. Be aware of Session::push because it will append always the new products in sessions. You should be using Session::put to be sure the products will be always updating.

這篇關于Laravel 在會話中存儲數組的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Laravel Eloquent Union query(Laravel Eloquent Union 查詢)
Overwrite laravel 5 helper function(覆蓋 Laravel 5 輔助函數)
laravel querybuilder how to use like in wherein function(laravel querybuilder 如何在 where 函數中使用 like)
The Response content must be a string or object implementing __toString(), quot;booleanquot; given after move to psql(響應內容必須是實現 __toString()、“boolean和“boolean的字符串或對象.移動到 psql 后給出) - IT屋-程
Roles with laravel 5, how to allow only admin access to some root(Laravel 5 的角色,如何只允許管理員訪問某些根)
Laravel Auth - use md5 instead of the integrated Hash::make()(Laravel Auth - 使用 md5 而不是集成的 Hash::make())
主站蜘蛛池模板: 亚洲 中文 欧美 日韩 在线观看 | 综合中文字幕 | 欧美精品乱码久久久久久按摩 | 国产精品美女www爽爽爽视频 | 欧美成人一区二区三区 | 午夜资源 | 能免费看的av | 福利片在线 | 精品一区二区免费视频 | 成人欧美一区二区 | 国产不卡一区 | 久久精品国产亚洲一区二区 | 中文字幕一区二区三区在线视频 | 亚洲综合视频 | 欧美精品一区在线发布 | 日韩三区在线 | 欧美一区在线视频 | h视频在线免费 | 成人一区二区三区在线观看 | 久久久成人网 | 日韩精品视频一区二区三区 | 91最新在线视频 | 日本精品久久久久 | 久久亚洲国产精品日日av夜夜 | 中文字幕亚洲一区二区va在线 | 精品视频免费在线 | 欧美色综合一区二区三区 | 亚洲黄色一级毛片 | 日韩欧美精品在线 | 欧美日韩精品中文字幕 | 亚洲一区欧美 | 精品成人佐山爱一区二区 | 久久久资源| 久久久久久久一区 | 在线视频成人 | 精品国产18久久久久久二百 | 国产免费视频 | 91久久精品日日躁夜夜躁欧美 | 亚洲最大的成人网 | 日本三级电影免费观看 | 免费观看的av毛片的网站 |