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

CodeFox's avatar

Structure question

Hi all

So I'm pretty confident that I'm coding something in the correct way, but would appreciate any feedback in case there's a better way of doing things.

I'm currently making a system where a user can book lessons. There are many types of lessons and these can repeat over a given period. For example a lesson might be on a Tuesday and a Friday every week for six weeks.

My structure is as follows:

  • Lesson has many Sessions
  • Lesson has many Students
  • Session has many Students
  • Session belongs to Teacher
  • Session has many SessionDates
  • SessionDates belongs to Session
  • Student belongs to one Session
  • Student belongs to one Lesson
  • Teacher has many Sessions

So the idea is that a Lesson acts kind of like a category. The user then provides the desired Session and based on the form they submit, my Controller will eventually use Carbon to loop over the dates and create entries in the session_dates table which has the session_id and the date.

So essentially I'm using logic to create a separate DB entry for each session in the given time period. Session can then access the SessionDates, and Lesson can access all of its sessions.

The Session contains the lesson_id and teacher_id.

The Student is assigned to a lesson and a session.

Does that make sense, and is there a better way of doing this or does my method make sense?

Thanks!

0 likes
6 replies
bashy's avatar

You should probably highlight a few table columns with backticks so we can scan over them and think about it properly. Right now it just looks like a wall of text.

Like so: teacher_id

CodeFox's avatar

@bashy - thanks, now done! Good suggestion!

@phpMick - Awesome I'd never heard of that tool before. Will give it a go :)

bashy's avatar

Can see better now.

From what I just checked (few minutes), it looks fine. Remember, you can always tweak when developing it if you find something can be done better.

Please or to participate in this conversation.