JSON column passed to view as string - Laravel - Vuejs2 JSON column passed to view as string - Laravel - Vuejs2 json json

JSON column passed to view as string - Laravel - Vuejs2


The solution I've gone with is decoding the data property manually in the VueJS2 template,

e.g. JSON.parse(data.key_which_is_actually_json).property_in_the_object

Any laravel based code (accessors, mutators etc) will fail when the property is transferred to VueJS2 component over HTTP as VueJS2 isn't smart enough to check properties in data receive and decode them.

VueJS2 seems to only decode the top level of properties in data received.


You may create your own Accessor and then convert the column to an array manually before retrieving the model.

public function getTheJsonColumnAttribute($value){    return json_decode($value, true);}

While it may seem laravel simply treated that column as a mere 'string' value when coming out, you can further validate that there is indeed a conversion.