Create Required Schemas


We are going to create four contents, posts, comments, categories, and tags, so we need four schemas.

Tags Schema

The first schema we are going to create is Tags schema navigate to http://localhost:3333/schemas/new and in the schema title enter Tags in Content Plural Title and Tag in Content Singular Title and tags in Content Plural Name and in SVG Icon we will put the tag icon from Heroicons:

html
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path
fill-rule="evenodd"
d="M17.707 9.293a1 1 0 010 1.414l-7 7a1 1 0 01-1.414 0l-7-7A.997.997 0 012 10V5a3 3 0 013-3h5c.256 0 .512.098.707.293l7 7zM5 6a1 1 0 100-2 1 1 0 000 2z"
clip-rule="evenodd"
/>
</svg>

Tags Schema Title Block

Next check the Restrict option and select Have Any Role in the condition type dropdown and select author and super roles in the condition value dropdown for the CREATE, UPDATE, and DELETE tabs of the Access Control List section, this will restrict the CREATE, UPDATE, and DELETE operations for the users that have author or super roles.

Schema ACL CREATE Tab Schema ACL UPDATE Tab Schema ACL DELETE Tab

Our Tags schema will have only one string field, so create a string field and put Title in Field Label and title in Field Name(in database) and mark the field as required.

Title Field

The full schema should look like:

Tags Schema

Click on the Save button to save the schema.

Categories Schema

Navigate to http://localhost:3333/schemas/new and in the schema title enter Categories in Content Plural Title and Category in Content Singular Title and categories in Content Plural Name and in SVG Icon we will put the folder icon from Heroicons:

html
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"
/>
</svg>

Categories Schema Title Block

Next check the Restrict option and select Have Any Role in the condition type dropdown and select author and super roles in the condition value dropdown for the CREATE, UPDATE, and DELETE tabs of the Access Control List section, this will restrict the CREATE, UPDATE, and DELETE operations for the users that have author or super roles.

Schema ACL CREATE Tab Schema ACL UPDATE Tab Schema ACL DELETE Tab

Our Categories schema will have two fields, string and Relation fields, we will create only the string field now then we will update the categories schema and create the Relation field, we want each category to have optional relation with itself! we want the ability for each category to have child categories and we can't create a relation for not existing schema, now create a string field and put Title in Field Label and title in Field Name(in database) and mark the field as required.

More info about what is the Relation field and how its woks you can read here.

Title Field

The full schema should look like:

Categories Schema

Click on the Save button to save the schema.

Next click on the Schemas List then on the edit icon that belongs to the categories row.

Schemas List And Click Edit

Now add the Relation field and enter Children in the Field Label and children in the Field Name(in database) and select Categories from the dropdown menu and check the repeatable option. The repeatable option will allow each category to have as many children as it wants.

Children Relation Field

Click on Update, the whole schema should look like:

Final Categories Schema

Posts Schema

Our post schema will have five fields, title, featured image, body, categories, and tags. Navigate to http://localhost:3333/schemas/new and in the schema title enter Posts in Content Plural Title and Post in Content Singular Title and posts in Content Plural Name and in SVG Icon we will put the pencil-alt icon from Heroicons:

html
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"
/>
</svg>

Posts Schema Title Block

Next check the Restrict option and select Have Any Role in the condition type dropdown and select author and super roles in the condition value dropdown for the CREATE, UPDATE, and DELETE tabs of the Access Control List section, this will restrict the CREATE, UPDATE, and DELETE operations for the users that have author or super roles.

Schema ACL CREATE Tab Schema ACL UPDATE Tab Schema ACL DELETE Tab

Next, create a string field and put Title in Field Label and title in Field Name(in database) and mark the field as required.

Title Field

Next, create the featured image field, create the Upload field and put Featured Image in Field Label and featuredImage in Field Name(in database).

Featured Image Field

Create a Textarea field and enter Body in Field Label and body in Field Name(in database).

Body Field

Now let's create the categories field, select the Relation field and enter Categories in Field Label and categories in Field Name(in database) and select Categories from the dropdown list as the schema that we want to create a relation with finally check the Repeatable? checkbox to be able to have one post in multiple categories.

Post Categories Relation

Finally, the Tags relation, will look exactly like the Categories above so add the Relation field, the title will be Tags and the name will be tags and select Tags from the dropdown list and check the Repeatable? checkbox.

Post Tags Relation

The full schema should look like:

Posts Schema

Click on the Save button to save the schema.

Comments Schema

The final schema we are going to create is Comments schema navigate to http://localhost:3333/schemas/new and in the schema title enter Comments in Content Plural Title and Comment in Content Singular Title and comments in Content Plural Name and in SVG Icon we will put the chat-alt-2 icon from Heroicons:

html
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M17 8h2a2 2 0 012 2v6a2 2 0 01-2 2h-2v4l-4-4H9a1.994 1.994 0 01-1.414-.586m0 0L11 14h4a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2v4l.586-.586z"
/>
</svg>

Comments Schema Title Block

Now for the Access Control List section check the Restrict option and select Authenticate in the condition type dropdown for the CREATE tab.

Schema ACL CREATE Tab

That means any authenticated user(logged-in user) can create comments.

For the UPDATE and DELETE tabs check the Restrict option and select Owner and click on the plus icon above the Owner a new condition should be created select Operator from the condition type dropdown and select OR as value, click the plus button above Operator and for the new condition select Have Any Role in the condition type dropdown and select author and super roles in the condition value dropdown.

Schema ACL UPDATE Tab Schema ACL UPDATE Tab

That means the comment's owner will be able to update and delete her/his comment also if the user has an author or super role will be able to do so as well.

Next, create the comment subject by creating a string field and put Subject in Field Label and subject in Field Name(in database) and mark the field as required.

Subject Field

Create a Textarea field and enter Body in Field Label and body in Field Name(in database).

Body Field

Finally create a Relation field and enter Post in Field Label and post in Field Name(in database) and select Posts, in the relation dropdown menu, this means each comment should be attached to one post, mark the field as required.

Comments Posts Relation

The full schema should look like:

Comments Schema

Click on the Save button to save the schema.