3 namespace BookStack\Activity\Models;
5 use BookStack\App\Model;
6 use BookStack\Permissions\Models\JointPermission;
7 use Illuminate\Database\Eloquent\Factories\HasFactory;
8 use Illuminate\Database\Eloquent\Relations\HasMany;
9 use Illuminate\Database\Eloquent\Relations\MorphTo;
13 * @property string $name
14 * @property string $value
15 * @property int $entity_id
16 * @property string $entity_type
17 * @property int $order
19 class Tag extends Model
23 protected $fillable = ['name', 'value', 'order'];
24 protected $hidden = ['id', 'entity_id', 'entity_type', 'created_at', 'updated_at'];
27 * Get the entity that this tag belongs to.
29 public function entity(): MorphTo
31 return $this->morphTo('entity');
34 public function jointPermissions(): HasMany
36 return $this->hasMany(JointPermission::class, 'entity_id', 'entity_id')
37 ->whereColumn('tags.entity_type', '=', 'joint_permissions.entity_type');
41 * Get a full URL to start a tag name search for this tag name.
43 public function nameUrl(): string
45 return url('/search?term=%5B' . urlencode($this->name) . '%5D');
49 * Get a full URL to start a tag name and value search for this tag's values.
51 public function valueUrl(): string
53 return url('/search?term=%5B' . urlencode($this->name) . '%3D' . urlencode($this->value) . '%5D');