Skip to content

Instantly share code, notes, and snippets.

@pvaladez
Last active August 23, 2024 19:30
Show Gist options
  • Select an option

  • Save pvaladez/27bc8b9e8b2830d05f38047318b975e5 to your computer and use it in GitHub Desktop.

Select an option

Save pvaladez/27bc8b9e8b2830d05f38047318b975e5 to your computer and use it in GitHub Desktop.
Payload CMS Blog Collection Schema
import type { CollectionConfig } from 'payload'
import { anyone } from '@/payload/access/anyone'
import { authenticated } from '@/payload/access/authenticated'
import { slugField } from '@/payload/fields/slug'
export const BlogPosts: CollectionConfig = {
slug: 'blog-posts',
admin: {
useAsTitle: 'title',
defaultColumns: ['title', 'slug', 'publishedAt'],
},
access: {
read: anyone,
update: authenticated,
create: authenticated,
delete: authenticated,
},
fields: [
{
name: 'title',
type: 'text',
required: true,
},
{
name: 'shortDescription',
type: 'textarea',
},
{
name: 'content',
type: 'code',
required: true,
admin: {
language: 'html',
},
},
{
name: 'thumbnailImage',
type: 'group',
fields: [
{
name: 'url',
type: 'text',
required: true,
},
{
name: 'alt',
type: 'text',
required: true,
},
],
},
{
name: 'publishedAt',
type: 'date',
admin: {
position: 'sidebar',
date: {
pickerAppearance: 'dayAndTime',
},
},
},
{
name: 'author',
type: 'relationship',
relationTo: 'users',
hasMany: false,
admin: {
position: 'sidebar',
},
},
slugField(),
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment