Laravel背包,列中显示地址(Json)

时间:2018-11-29 20:42:18

标签: php json laravel backpack-for-laravel

我想显示来自地址json的名称字段(使用algolia),我该怎么做?

我尝试过:

$this->crud->addColumn([
     'name' => "address",
     'label' => 'Address',
     'type' => 'array',
]);

但是无法工作。而且,它总是返回错误。

在预览中,我也想显示完整的地址,但只返回json。

enter image description here

预先感谢

1 个答案:

答案 0 :(得分:1)

设法使用自定义字段。

控制器:

 $this->crud->addColumn([
            'name' => 'address', //db field
            'label' => "Address", 
            'type' => 'customAddress' //name of custom created custom field
 ]);

在以下位置创建自定义字段:resources \ views \ vendor \ backpack \ crud \ columns 我将其命名为“ customAddress.blade.php”

自定义字段:

{{-- customAddress--}} 
<?php $object  = (object) json_decode($entry['address'], true); ?>
<span><?php echo $object->value; ?></span>

您还可以使用foreach来显示诸如$ object-> name,$ object-> country等内容。

希望这对某人有帮助。