4 years ago

Array Casting of serialized returns null

Posted 4 years ago by jsrosas

Hi all, I have an issue with casting a serialized 'sku' attribute to array. In my database its saved as a:2:{i:0;s:7:"sophia1";i:1;s:3:"dog";} On my order I am casting sku to array

protected $casts = [
        'sku' => 'array',

Then I retrieve a single order on my controller and do dd($order->sku); This returns null. But if I remove the cast and manually do unserialize($order->sku) I get my desired array. I cannot just pass unserialized array to the view as it gives me a htmlentities() error.

Please sign in or create an account to participate in this conversation.