Yes, this can be done w/ hooks and access control. Here is an example collection:
const Posts: CollectionConfig = {
slug: 'posts',
hooks: {
beforeChange: [
({ req, operation, data }) => {
if (req.user) {
if (operation === 'create') {
data.updatedBy = req.user.id;
data.createdBy = req.user.id;
} else if (operation === 'update') {
data.updatedBy = req.user.id;
}
return data;
}
},
],
},
fields: [
{
name: 'createdBy',
type: 'relationship',
relationTo: 'users',
access: {
update: () => false,
},
admin: {
readOnly: true,
position: 'sidebar',
condition: (data) => !!data?.createdBy,
},
},
{
name: 'createdBy',
type: 'relationship',
relationTo: 'users',
access: {
update: () => false,
},
admin: {
readOnly: true,
position: 'sidebar',
condition: (data) => !!data?.createdBy,
},
},
// Other fields
],
};
export default Posts;
This will now show in the admin sidebar
Is it possible to add these two fields' information in the area of the screenshot I took above?
same question?
is it possible to show the users name on top of the collection where we have createdat and updatedat?
same request
Star
Discord
online
Get dedicated engineering support directly from the Payload team.