ousid's avatar
Level 3

Opening Hours & Time Availability

I have a laravel project and I'm wondering about the best way to implement opening hours and availability in Listing table.

Step to produce:

A listing model has these columns:

  • title
  • city
  • address
  • availability time
  • opening hours

I think about making a opening_hours table and make relation between the opening_hours table and listing like so:

Opening Hours table has

  • day

  • opening time

  • closing time

  • listing_id

  • Listing has many opening hours.

  • Opening Hours belongs to listing.

Any Ideas about how to implement those two [Opening hours & time availability] I'll be appreciated.

Thanks in advance.

0 likes
9 replies
bugsysha's avatar

To me that sounds like an overkill. Those times do not change that often, right?

ousid's avatar
Level 3

Hey, @bugsysha thanks for replying

It depends on the listing creator.

What do you suggest?

bugsysha's avatar

I would check if I can fit it into environment variable and use that. If not, simple json column until I have a need for something more complex.

Show an example of data you were planning to store and then you can get a more direct answer.

Snapey's avatar
Snapey
Best Answer
Level 122

If you don't need to interact with the data (for example, changing some view based on the current time and store open/store closed) then I would probably hold it as a serialized array or as json in a single field.

ousid's avatar
Level 3

Hey, @snapey.

Yes, I need to interact with the data not just showing the opening hours.

siangboon's avatar

snapey suggested serialized array/json seem good enough...

ousid's avatar
Level 3

Yup, That's exactly what I'm trying to do right now.

I figure out a solution, which is to store all the opening hours/available time on json column and it works very well. After that I'll try to manage the result with Opening Hours spatie package.

ousid's avatar
Level 3

Thanks For y'll, I really appreciate it

Please or to participate in this conversation.