| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\App\Models; |
| 4 |
|
| 5 |
use FluentBoards\App\Services\Constant; |
| 6 |
use FluentBoards\Framework\Database\Orm\Builder; |
| 7 |
|
| 8 |
class Label extends BoardTerm |
| 9 |
{ |
| 10 |
public static function boot() |
| 11 |
{ |
| 12 |
parent::boot(); |
| 13 |
static::creating(function ($model) { |
| 14 |
$model->type = $model->type ?: 'label'; // default type is label |
| 15 |
}); |
| 16 |
|
| 17 |
static::addGlobalScope('type', function (Builder $builder) { |
| 18 |
$builder->where('type', '=', 'label'); |
| 19 |
}); |
| 20 |
} |
| 21 |
|
| 22 |
public function tasks() |
| 23 |
{ |
| 24 |
return $this->belongsToMany( |
| 25 |
Task::class, |
| 26 |
'fbs_relations', |
| 27 |
'foreign_id', |
| 28 |
'object_id' |
| 29 |
)->withTimestamps()->wherePivot('object_type', Constant::OBJECT_TYPE_TASK_LABEL)->withPivot('settings', 'preferences'); |
| 30 |
} |
| 31 |
} |
| 32 |
|