0, 'group_id' => 0, 'description' => '', 'link' => '', 'enabled' => true, ]; /** * The attributes that should be casted to native types. * * @var string[] */ protected $casts = [ 'name' => 'string', 'description' => 'string', 'status' => 'int', 'order' => 'int', 'link' => 'string', 'group_id' => 'int', 'enabled' => 'bool', 'deleted_at' => 'date', ]; /** * The fillable properties. * * @var string[] */ protected $fillable = [ 'name', 'description', 'status', 'tags', 'link', 'order', 'group_id', 'enabled', ]; /** * The validation rules. * * @var string[] */ public $rules = [ 'name' => 'required|string', 'status' => 'int|required', 'link' => 'url', ]; /** * The searchable fields. * * @var string[] */ protected $searchable = [ 'id', 'name', 'status', 'order', 'group_id', 'enabled', ]; /** * The sortable fields. * * @var string[] */ protected $sortable = [ 'id', 'name', 'status', 'order', 'group_id', 'enabled', ]; /** * Get the group relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function group() { return $this->belongsTo(ComponentGroup::class, 'group_id', 'id'); } /** * Get the incidents relation. * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function incidents() { return $this->hasMany(Incident::class, 'component_id', 'id'); } /** * Get the tags relation. * * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany */ public function tags() { return $this->belongsToMany(Tag::class); } /** * Finds all components by status. * * @param \Illuminate\Database\Eloquent\Builder $query * @param int $status * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeStatus(Builder $query, $status) { return $query->where('status', $status); } /** * Finds all components which don't have the given status. * * @param \Illuminate\Database\Eloquent\Builder $query * @param int $status * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNotStatus(Builder $query, $status) { return $query->where('status', '<>', $status); } /** * Finds all components which are enabled. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeEnabled(Builder $query) { return $query->where('enabled', true); } /** * Finds all components which are disabled. * * @param \Illuminate\Database\Eloquent\Builder $query * * @return \Illuminate\Database\Eloquent\Builder */ public function scopeDisabled(Builder $query) { return $query->where('enabled', false); } /** * Returns all of the tags on this component. * * @return string */ public function getTagsListAttribute() { $tags = $this->tags->map(function ($tag) { return $tag->name; }); return implode(', ', $tags->toArray()); } /** * Get the presenter class. * * @return string */ public function getPresenterClass() { return ComponentPresenter::class; } }