Nevermind-- I spent way too much time messing with this and never noticed that you have to actually call the attribute for it to be cast as expected. So looking at the raw record, it's still in json format ($r = App\Configuration::first();), but if you then call $r->additional_options it shows the variable cast as an array, as expected.
Model json casting to array not working
I have a postgres table with a couple of jsonb columns defined. Obviously the data in those columns is json. I assumed all I'd need to do would be to add the $casts property in my model to ensure the json is cast to / from an array when it's read out or written to, as it's documented here: https://laravel.com/docs/5.3/eloquent-mutators#array-and-json-casting
Here's my model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Configuration extends Model
{
protected $casts = [
additional_options' => 'array',
];
// etc.
However, when I read out the first row with tinker ($r = App\Configuration::first();) the data is still in json format:
additional_options: "{"batch_size": 2000, "version": "1.7.2", "batch_process": true, "password": null}",
What am I doing wrong here?
Please or to participate in this conversation.
