I have a table named settings
, in it, there are several columns, id
,company_id
, key
, value
.
In my Laravel model for Setting, I have the following cast:
protected $casts = [
'value' => 'array',
];
But when I go to retrieve data that has been stored, I can't.
For example, I have a record with the following value
: "{\"default_remit_address\":\"2395\"}"
And when I go to retrieve the record in a Blade, it does pull it up correctly, but I'm not sure how to grab a specific value from the value
field (like default_remit_address).
If I print the return "{{$settings->value}}"
directly in the Blade, this is what I get:
{"default_remit_address":"2395"}
So how can I go one level deeper?
As this json object is being cast to an
Array
, you can just use regular array syntax to access it's contents.or in your blade template