unserialize data in laravel
You can use map()
method to unserialize cart property for the whole collection:
$orders = $orders->map(function($i) { $i->cart = unserialize($i->cart); return $i;});
Alternatively, you could use an accessor to automatically unserialize property:
public function getCartAttribute($value){ return unserialize($value);}
Or just unserialize the data in Blade:
@foreach ($orders as $order) {{ unserialize($order->cart)->someData }}@endforeach
Sure you can use built-in unserialize()
function from previous answers.
But
Avoid using unserialize()
in your code because of exloit:
https://www.notsosecure.com/remote-code-execution-via-php-unserialize/https://www.php.net/manual/en/function.unserialize.php
I would use secure simple lib from Magento 1:https://github.com/bragento/magento-core/tree/1.9/lib/Unserialize
$parser = new Unserialize_Parser();$parser->unserialize($yourStringWithArray)
serialize is just a built-in, variable handling, PHP function. The counterpart of this is unserialize.