首页 > 解决方案 > laravel livewire 中的数组编辑

问题描述

所以我的模型中有一个 $information ,其中包含类似 JSON

{
"key": "value",
"key1: "value1"
}

我想要做的是制作一个能够添加和编辑这个模型的crud,值得注意的是 $information 是动态的并且可能有很多行,我使用 eloquent::json 将此数据存储在数据库中并使用json_decode($信息,1)。我需要的是一个用于编辑和创建表单的 HTML 结构。(实际上我有这样的东西:

 <template x-for="(field, index) in fields" :key="index">
    <tr>
        <td x-text="index + 1"></td>
        <td><input wire:model="information" style="width: 190px" type="text" name="txt1[]"></td>
        <td><input wire:model="information" style="width: 190px" type="text" name="txt2[]"></td>
        <td>
            <button type="button" class="btn btn-danger btn-small"
                    @click="removeField(index)">&times;
            </button>
        </td>
    </tr>
</template>
</tbody>
<tfoot>
<tr>
    <td colspan="4" class="text-right">
        <button type="button" class="btn btn-info"
                @click="addNewField()">+ Add Row
        </button>
    </td>
</tr>
</tfoot>

但它在从模型加载数据时遇到问题,也无法保存任何内容。谢谢你的帮助~

标签: phphtmllaraveleloquent

解决方案


推荐阅读