zerosAndOnes's avatar

Question about Spatie Opening Hours

I am looking to use this package for an application I am working on. This application will have more than one user and each user will have their own opening hours.

I am used to packages being migrated to DB and traits being used in order to query the DB for a particular model's record, but that isnt same for spatie opening hours package.

My question is: how do I use this package in a way that multiple users can save their business hours, and I can query for a user's business hour. And how can this be updated if the user decides to update their business info (opening hours included)?

I have thought about saving the business hour as a column in my businesses table and query it using the $business->openingHours->isOpen(), but I am not sure if this is correct and I havent been able to think of a way to update the hours... Maybe filling the days with the new requests, but even with that, how do I fetch the previous requests to fill the form fields for updating?

Thanks.

Package: https://github.com/spatie/opening-hours

0 likes
4 replies
tisuchi's avatar

@cyberkid007 The package's documentation seems it's for single user uses only. I guess it's the scope of the package.

1 like
zerosAndOnes's avatar

Thanks Snapey.

From what I collected from the links you sent, it’s better to not store json data in the DB. So I am planning on creating a table for business hours and use a foreign key to relate to businesses.

What will be the best way to query if a business is open using carbon?

Also, this will be tricky to store as I wanted to have one form for all the business information, so there’s no way to click on submit and the business hours, although going to a different table, will also be saved.

Kindly help clear this doubt of mine. Thanks.

simobarba's avatar

Hello, do you know how to translate the days of spatie opening hours to other languages? I use for example this code and I 'd like to show the days name in Italian {{ $place->working_hours->nextOpen(now())->format('l H:i') }}

thanks

Please or to participate in this conversation.