Unable to add new form field #2345
-
I've just started using Twill this week for a new project and am trying to add a new content type. I've been following the simple page builder guide. After completing that guide, I'm now trying to add my own custom fields to a new content type ('newsItems'). As far as I can tell from the docs, all I need to do to add e.g. 'Author' and 'Article date' fields is to update the public function getForm(TwillModelContract $model): Form
{
$form = parent::getForm($model);
$form->add(
Input::make()->name('description')->label('Description')->translatable()
);
$form->add(
Medias::make()->name('cover')->label('Cover image')
);
$form->add(
DatePicker::make()->name('article_date')->withoutTime()
);
$form->add(
Input::make()->name('author')->label('Author')->translatable()
);
$form->add(
BlockEditor::make()
);
return $form;
} I don't need to create any migrations, the actual data will just be stored in I'm really struggling to get this to work. The data occasionally gets saved i.e. this query brings back the data I saved: SELECT id, JSON_EXTRACT(payload, '$.author'), JSON_EXTRACT(payload, '$.article_date') from news_item_revisions But my custom data (author, article date) is never displayed when I refresh the CMS editor, and so with the next save it gets wiped (unlike the description field, which behaves properly). I think I must have missed something pretty fundamental... |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hi @stuartmcgill, each field you add at the form level needs a column in your main model table and it needs to be added to the model |
Beta Was this translation helpful? Give feedback.
-
Each field documentation page is indicating the migration needs if any, eg. https://twillcms.com/docs/form-fields/input.html#:~:text=A%20migration%20to,1 |
Beta Was this translation helpful? Give feedback.
-
Fields like medias, files, browsers, and block editors do not need migrations because they use polymorphic tables from Twill ( |
Beta Was this translation helpful? Give feedback.
-
Ensure Field Names Match Database: |
Beta Was this translation helpful? Give feedback.
Hi @stuartmcgill, each field you add at the form level needs a column in your main model table and it needs to be added to the model
$fillable
array as well. When working with blocks, you don't need any migration, but outside of blocks, data is stored using standard Laravel Eloquent models and attributes.