我正在使用Spatie在我的网站上记录活动。我创建了一个表,其中将显示来自activity_log数据库表的数据。从数据库中检索数据没有问题,但是我的问题是,每当我显示properties
列中的值时,它只会显示[object Object]
。
数据表的外观如下:
activity_log
数据库表中的实际值是这样:
这是我的控制器中的代码段:
public function datatable_Activities()
{
$data = Activity::all()->where('causer_id', '=', Auth::user()->id);
return Datatables::of($data)->make(true);
}
用于在刀片文件中显示数据的代码段:
<script>
$(function () {
$("#activity_table_log").DataTable({
responsive:true,
processing:true,
pagingType: 'full_numbers',
stateSave:false,
scrollY:true,
scrollX:true,
ajax:"{{route('datatable_Activities')}}",
order:[0, 'desc'],
columns:[
{data:'log_name', name: 'log_name'},
{data:'description', name: 'description'},
{data:'subject_id', name: 'subject_id'},
{data:'properties', name: 'properties'},
{data:'created_at', name: 'created_at', searchable: false, sortable:false},
]
});
});
</script>
我已经尝试过
json_decode()
,但是很遗憾,它无法正常工作。 如何像存储在properties
中的值一样正确显示它 数据库中的列而不是[object Object]
?
但是,当我在开发人员工具中检查响应时,它会从数据库中准确检索属性值。
这是我要放入数据表中的示例嵌套JSON对象:
{
"id":6,
"log_name":"PurchaseH",
"description":"A purchase h has been updated",
"subject_id":1,
"subject_type":"App\\Model\\Purchase\\PurchaseH",
"causer_id":1,
"causer_type":"App\\User",
"properties":{
"attributes":{
"total":1250000
},
"old":{
"total":null
}
},
"created_at":"2020-06-14T09:04:34.000000Z",
"updated_at":"2020-06-14T09:04:34.000000Z"
},
P.S。我正在使用最新的Google chrome,Laravel Framework和Spatie。