Files
Scheduler/app/Models/Bot.php
2025-08-30 16:11:06 +02:00

40 lines
845 B
PHP

<?php
namespace App\Models;
use Cron\CronExpression;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Lorisleiva\CronTranslator\CronTranslator;
class Bot extends Model
{
protected $fillable = [
'name',
'class',
'config',
'schedule',
'enabled'
];
protected $casts = [
'config' => 'array',
];
public function nextDue(): Attribute
{
return Attribute::make(
get: function () {
$cron = new CronExpression($this->schedule);
return $cron->getNextRunDate()->format('Y-m-d H:i:s');
}
);
}
public function cronToHuman(): Attribute
{
return Attribute::make(
get: fn () => CronTranslator::translate($this->schedule));
}
}