Laravel Nova-将数据库json列映射到字段 [英] Laravel Nova - Map database json column to field

查看:316
本文介绍了Laravel Nova-将数据库json列映射到字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为attributesjson列类型的数据库模型.此列将包含模型的其他详细信息.

I have a database model with json column type called attributes. This column will contain additional details of the model.

例如: attributes : {'desc' : 'test', 'width' : '500'}.

我想在Laravel管理资源中的html字段中的attributes列中显示单个属性(desc& width).

I would like to display individual attribute (desc & width) in attributes column as a html field in Laravel admin resource.

我检查了受支持的字段类型,但没有似乎不支持.

I checked supported field types and doesn't seem supports.

有人建议我该怎么做吗?

Any suggestions how I can do this?

推荐答案

我不确定这是否是建议的答案,但我已经找到一种适合您的方法.

I'm not sure if it's the recommended answer but i've found a way that should work for you.

使用口才突变体:口才突变体

然后,定义一个getDescAttributesetDescAttribute并将其像模型中的属性一样以新星的形式传递给它,

Then you define a getDescAttribute and a setDescAttribute and pass it in nova like a property on the model like so:

Text::make('Desc', 'desc')

希望这会有所帮助.

这篇关于Laravel Nova-将数据库json列映射到字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆