Laravel How can I configure "reserved_at" in the jobs table

Viewed 30

I want to use Carbon::today()->addMonth() as default value of reserved_at column in jobs table then I will use ite in the job in the way of

    if(reserved_at == Carbon->today())
      { 
          //execution
      } else {
          //don't
      }
2 Answers

You can set reserved_at in model's creating event within the model boot() method, like that add following method in Job model:

public static function boot()
    {
        parent::boot();

        static::creating(function ($model) {
            $model->reserved_at = Carbon::today()->addMonth();
        });
    }

It will append reserved_at field value in model when you storing data using eloquent methods.

Note: It'll not work with insert() query builder method.

I figured it out it's by using the function of the class InteractsWithQueue ->delay(Carbon::now()->addMinutes(5)) with the dispatch function

Related