'Store functions in database

I have public holidays stored in an array

    $holiday["Christi Himmelfahrt"]       = strtotime("+39 day",easter_date($year));
    $holiday["Pfingstmontag"]             = strtotime("+50 day",easter_date($year));
    $holiday["Fronleichnam"]              = strtotime("+60 day",easter_date($year));

and some more...

I was thinking about storing them in a table, because I want to add more countries. Is this a good idea? I was thinking to store it like this:

        Schema::create('holidays', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('name');
        $table->text('calculation');
        $table->string('country',2)->default('AT');
        $table->foreign('country')->references('iso_code')->on('countries');
        $table->timestamps();
    });

But how would I get this calculated dates? And again: is this a good idea at all?



Solution 1:[1]

What about adding another column after_days where you save "39" for example and after you query the database you can do this

$holiday = Holiday::select('after_days')->where('id, '=', $id)->first();
strtotime("+".$holiday->after_days." day", easter_date($year));

Assuming that the year is static and you don't need to save it in database.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1