Required option not working on files section?


I’m trying to make a file section (images) required: true to prevent a page being published without an image. Is required working only on fields? (Of course I’ll also check with isNotEmpty())


I’d suggest using min: 1 instead:

isNotEmpty() will not work on a files section. Sections don’t save any data.

If it’s the only files section you can use $page->hasFiles(). When using multiple files sections with different templates you can use $page->files()->template('yourtemplate')->count() as a condition.

See this page for an explanation of the section/field difference:

1 Like

isNotEmpty() instead of count() would also work.

Thanks! I will try the min option, completely forgot about that. :confused: