laravelshoppingcart icon indicating copy to clipboard operation
laravelshoppingcart copied to clipboard

unserialize(): Error at offset 56 of 999 bytes

Open root120 opened this issue 6 years ago • 1 comments

Why I am getting "unserialize(): Error at offset 56 of 999 bytes" ?. actually I want to store cart_data with user location.

root120 avatar Dec 07 '18 17:12 root120

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));
}

ggwebdev avatar Aug 20 '20 12:08 ggwebdev