php - 在 JSON 列中存储多个字段 (Nova CMS)

标签 php laravel laravel-nova

我有一个 posts 表,其中有一个 json 列“read_more_section”。

我想在该列上存储有关 NOVA CMS 上某些字段的信息(标题、描述、标签和链接)。你知道如何在 Nova 中正确地做到这一点吗?将这 4 个字段中输入的内容存储在 json 列“read_more_section”中?

 public function fields(Request $request)
    {
        return [
            ID::make(__('ID'), 'id')->sortable(),

                new Panel('Read More Section', [                

                    Text::make('Title')->rules(['max:255']),
                    Text::make('Description'),
                    Text::make('Label'),
                    Text::make('Link'),

                    
                ]),

               
        ];
    }

最佳答案

您可以创建一个 getter 和 setter,捕获这些字段的值并将其转换为 json 对象。

或者你可以用https://github.com/whitecube/nova-flexible-content来做到这一点 只需在布局中将限制设置为 1。

https://whitecube.github.io/nova-flexible-content/#/?id=limiting-layouts-per-type https://whitecube.github.io/nova-flexible-content/#/?id=limiting-layouts

Nova资源

 public function fields(Request $request)
    {
        return [
            ID::make(__('ID'), 'id')->sortable(),

                new Panel(__('Read More'), [                

                    Flexible::make('Specifications', read_more_section)
                       ->addLayout(ReadMoreLayout::class)
                       ->limit(1),
                    
                ]),

               
        ];
    }

ReadMoreLayout.php

class ReadMoreLayout extends Layout
{
    /**
     * The layout's unique identifier
     *
     * @var string
     */
    protected $name = 'title';

    /**
     * The displayed title
     *
     * @var string
     */
    protected $title = 'Read More Section';

    protected $limit = 1;

    /**
     * Get the fields displayed by the layout.
     *
     * @return array
     */
    public function fields()
    {
        return [
                Text::make('Title')->rules(['max:255']),
                Text::make('Description'),
                Text::make('Label'),
                Text::make('Link'),
        ];
    }
}

关于php - 在 JSON 列中存储多个字段 (Nova CMS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72114338/

相关文章:

php - 谷歌应用引擎 : WARNING: The Cloud SDK no longer ships runtimes for PHP 5. 4

laravel-nova - 如何在 Laravel Nova 中以编程方式重新加载 ResourceTable?

php+mysql : copying a row from one table to another

php - 如何跨多个页面传递多个变量?

php - Apache 文件所有权/组

javascript - 使用 ajax 和 jquery 上传文件和表单

php - 无法用php连接数据库

php - 在laravel中将数字四舍五入到最接近的9

php - Laravel Nova 不坚持新模型

javascript - Laravel Nova 覆盖 vue 组件导致 [Vue warn] : Error compiling template