Initial work
This commit is contained in:
39
app/Models/Bot.php
Normal file
39
app/Models/Bot.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user