Hi all,
I have a model that includes a field in the database (called answers) where I am saving json data. Eloquent schema is below:
Schema::create('assessments', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->string('identifier');
$table->string('answers')->nullable(); //this is the filed where json data is saved
$table->timestamps();
$table->datetime('completed_at')->nullable();
$table->softDeletes();
});
When I retrieve one of these items from the database and send it to a view, the answers field is not parsed as json but kept as a string. Like so:
{
"id": 4,
"user_id": "1",
"identifier": "test",
"answers": "[{\"question\":{\"id\":\"question1\",\"title\":\"Question 1\"},\"answer\":\"test answer\"},{\"question\":{\"id\":\"question2\",\"title\":\"Question 2\"},\"answer\":\"Yes\"}]",
"created_at": "2016-04-20 08:51:21",
"updated_at": "2016-04-21 14:14:56",
"completed_at": null,
"deleted_at": null
}
Because of this, I am finding it difficult to parse the answers as json in javascript. Is there a way to easily do this?
Thanks!