laravelshoppingcart
laravelshoppingcart copied to clipboard
unserialize(): Error at offset 56 of 999 bytes
Why I am getting "unserialize(): Error at offset 56 of 999 bytes" ?. actually I want to store cart_data with user location.
The problem is caused by special characters (Ex.: O:32:"Darryldecode\Cart\CartCollection":1:{s:8:"\x00*\x00) that are generated on serialization. The problem was solved using base64_encode after serializing and base64_decode before deserializing the content. As can be seen below:
On DatabaseStorageModel Class:
public function setCartDataAttribute($value) {
$this->attributes['cart_data'] = base64_encode(serialize($value));
}
public function getCartDataAttribute($value) {
return unserialize(base64_decode($value));
}