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

AbdallahSabri's avatar

Storing (Days) in database

I'm working on listing schedule, I want to store all of these values in a table called listing_working_hours I want to store all of the following data

(day, from_time, to_time, listing_id)

This will shows that listing (x) is open on (Friday from 8:00 AM to 4:pm) and on (Saturday from 6:00 am to 6:00 pm) ..etc.

what is the best practice to store day (integer value, enum, relation to another table ..etc.)?

0 likes
3 replies
topvillas's avatar

You don't store the day. Just use a datetime type, use the dates array in your model and use Carbon to format the date,

m7vm7v's avatar

I would create a new migration with timestamps as Laravel cast these to Carbon and you can do a lot in the output.

public function up()
    {
        Schema::create('listing_working_hours', function (Blueprint $table) {
            $table->increments('id');
            $table->listing_id('listing_id'); //I would stick with only the id and delete this one
            $table->timestamp('from');
            $table->timestamp('to');
            $table->timestamps();
        });
    }

so when you create a a new data in that table you would have all the dates you need in full format.

Then in your model -

    /**
     * The attributes that should be mutated to dates.
     *
     * @var array
     */
    protected $dates = [
        'from',
        'to',
        'created_at',
        'updated_at'
    ];

Please or to participate in this conversation.