Support the ongoing development of Laravel.io →
Database Eloquent Laravel

Hello Everyone! I'm working on a multi-store system and I would need to store efficently working days and working hours (aka schedule).

For days i've it figured. I store a int for Opening Days and made constants for everyday and use bitwise operator, so I can use

if (OpeningDays & MONDAY) return true

I also want to store in the database the opening hours, the way I figured was another table like

OpeningHours
id | shop_id | day | from  | to
 1 |    1    |  1  | 10:30 | 14:30 // Monday

BUT, I think this is owful for query performance, because for each store that opens every day I have a minimum of 7 registers in the OpeningHours table, OR more (double) if they have more than one in the same day, like 10:30 to 14:30 and 19:00 to 23:00.

So I'm trying to figure the most efficient way to storing opening hours for each store.

Thank you!!

Last updated 2 years ago.
0
Solution

So, I finally end up doing another bit parser for the working hours, 1 bit each half hour. So I have 48 bits, if its open at that time, you have 1, otherwise 0. Since my need is for business hours (stores), I don't mind it to be each half hour, no store has a opening or closing time like 22:10, so it works.

I'll make an article with the code and approach.

Thanks!

0
Solution selected by @ngenen

Sign in to participate in this thread!

PHPverse

Your banner here too?

Nicolas Genen ngenen Joined 9 Sep 2022

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.