Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eriktobben's avatar

How to create a "all purpose" activity/log table

Hi!

I am about to start creating an activity/log feature on my site, and I am not sure how to solve this using a single table.

I want to log actions like: user sent a sms to, case updated, customer updated, status changed etc.

I was thinking about doing it this way: *id primary

*customer_id int nullable

*case_id int nullable

*type int

*title var

*text text

*user_id int null

*timestamps datetime

Will it be problematic that multiple fields will potentially have NULL value?

I have also considered this: *id primary

*type int

*external_id int (for case_id, customer_id etc.)

*title var

*text text

*user_id int

*timestamps datetime

Is there a better way of doing this?

0 likes
4 replies
ohffs's avatar

You might want to look into 'polymorphic' relations. That's what I've just been using for a log table. There's a video on here if you search or the laravel docs have a section on it too.

1 like
eriktobben's avatar

Thanks to both of you! I will check the video and documentation!

Please or to participate in this conversation.