'required|integer', 'component_id' => 'integer', 'name' => 'required', 'status' => 'required|integer', 'message' => 'required', ]; /** * The fillable properties. * * @var string[] */ protected $fillable = ['user_id', 'component_id', 'name', 'status', 'message', 'scheduled_at']; /** * The accessors to append to the model's serialized form. * * @var string[] */ protected $appends = ['humanStatus']; /** * The attributes that should be mutated to dates. * * @var string[] */ protected $dates = ['scheduled_at', 'deleted_at']; /** * Finds all scheduled incidents (maintenance). * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeScheduled($query) { $timestamp = (new Date())->setTimezone(SettingFacade::get('app_timezone'))->format('Y-m-d H:i:s'); return $query->where('status', 0)->whereRaw('scheduled_at >= "'.$timestamp.'"'); } /** * Finds all non-scheduled incidents. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNotScheduled($query) { return $query->where(function ($query) { $timestamp = (new Date())->setTimezone(SettingFacade::get('app_timezone'))->format('Y-m-d H:i:s'); return $query->whereNull('scheduled_at')->orWhereRaw('scheduled_at <= "'.$timestamp.'"'); }); } /** * Get presenter class. * * @return string */ public function getPresenter() { return 'CachetHQ\Cachet\Presenters\IncidentPresenter'; } /** * An incident belongs to a component. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function component() { return $this->belongsTo('CachetHQ\Cachet\Models\Component', 'component_id', 'id'); } /** * Returns a human readable version of the status. * * @return string */ public function getHumanStatusAttribute() { $statuses = trans('cachet.incidents.status'); return $statuses[$this->status]; } /** * Returns whether the "incident" is scheduled or not. * * @return bool */ public function getIsScheduledAttribute() { return $this->getOriginal('scheduled_at'); } /** * Get the transformer instance. * * @return \CachetHQ\Cachet\Transformers\IncidentTransformer */ public function getTransformer() { return new IncidentTransformer(); } }