'integer', 'hidden' => 'boolean', ]; protected $appends = [ 'frequency_label', ]; public function server(): BelongsTo { return $this->belongsTo(Server::class); } public function getCrontabAttribute(): string { $data = ''; $cronJobs = $this->server->cronJobs()->where('user', $this->user)->get(); foreach ($cronJobs as $key => $cronJob) { $data .= $cronJob->frequency.' '.$cronJob->command; if ($key != count($cronJobs) - 1) { $data .= "\n"; } } return $data; } public function addToServer(): void { dispatch(new AddToServer($this))->onConnection('ssh'); } public function removeFromServer(): void { $this->status = CronjobStatus::DELETING; $this->save(); dispatch(new RemoveFromServer($this))->onConnection('ssh'); } public function getFrequencyLabelAttribute(): string { $labels = [ '* * * * *' => 'Every minute', '0 * * * *' => 'Hourly', '0 0 * * *' => 'Daily', '0 0 * * 0' => 'Weekly', '0 0 1 * *' => 'Monthly', ]; if (isset($labels[$this->frequency])) { return $labels[$this->frequency]; } return $this->frequency; } }