'int', 'visible' => 'integer', ]; /** * The attributes that should be mutated to dates. * * @var string[] */ protected $dates = ['scheduled_at', 'deleted_at']; /** * The fillable properties. * * @var string[] */ protected $fillable = [ 'component_id', 'name', 'status', 'visible', 'message', 'scheduled_at', 'created_at', 'updated_at', ]; /** * The validation rules. * * @var string[] */ public $rules = [ 'component_id' => 'integer', 'name' => 'required', 'status' => 'required|integer', 'visible' => 'required|boolean', 'message' => 'required', ]; /** * Finds all visible incidents. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeVisible($query) { return $query->where('visible', 1); } /** * Finds all scheduled incidents (maintenance). * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeScheduled($query) { return $query->where('status', 0)->where('scheduled_at', '>=', Carbon::now()); } /** * 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) { return $query->whereNull('scheduled_at')->orWhere('scheduled_at', '<=', Carbon::now()); }); } /** * An incident belongs to a component. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function component() { return $this->belongsTo(Component::class, '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') !== null; } /** * Get the presenter class. * * @return string */ public function getPresenterClass() { return IncidentPresenter::class; } }