You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Filament框架下Picklist及选项数据保存逻辑技术求助

问题描述

我在模态框中创建了PicklistOptionResource和PicklistResource两个资源,它们是存储和管理数据的核心组件。数据传入后,我需要实现对应的保存逻辑,确保信息在初始传入后仍能持久留存。相关代码实现如下:

Section::make('Picklist Section')
    ->hidden(function ($get) {
        $allowedType = [FieldTypeEnums::PICK_LIST];
        return !in_array($get('field_type'), $allowedType);
    })
    ->schema([
        Select::make('Picklist')
            ->label('Picklist')
            ->options(Picklist::pluck('name'))
            ->createOptionForm([
                TextInput::make('name')
                    ->label(strval(__('cranberry-muffin::cranberry-muffin.form.input.picklists.name')))
                    ->afterStateUpdated(function (Closure $set, $state) {
                        $set('slug', Str::slug($state));
                    })
                    ->reactive()
                    ->required(),
                TextInput::make('slug')
                    ->label(strval(__('cranberry-muffin::cranberry-muffin.form.input.picklists.slug')))
                    ->required(),
                Textarea::make('description')
                    ->label(strval(__('cranberry-muffin::cranberry-muffin.form.input.picklists.description')))
                    ->columnSpan(2),
                Repeater::make('add_picklist_options')
                    ->label(strval(__('cranberry-muffin::cranberry-muffin.repeater.picklist-options')))
                    ->schema([
                        TextInput::make('name')
                            ->label(strval(__('cranberry-muffin::cranberry-muffin.form.input.picklist-options.name')))
                            ->afterStateUpdated(function (Closure $set, $state) {
                                $set('slug', Str::slug($state));
                            })
                            ->reactive()
                            ->required(),
                        TextInput::make('slug')
                            ->label(strval(__('cranberry-muffin::cranberry-muffin.form.input.picklist-options.slug')))
                            ->required(),
                    ])->columnSpanFull()
                    ->columns(2)
                    ->createItemButtonLabel('Add New Picklist Option')
            ])->columns(2)
    ])
    ->hidden(function ($get) {
        $allowedType = [FieldTypeEnums::PICK_LIST];
        return !in_array($get('field_type'), $allowedType);
    }),

内容的提问来源于stack exchange,提问作者Sidharth Kumar Samal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 06:55:25