3 namespace BookStack\Actions;
5 use BookStack\Auth\Permissions\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 $order
17 class Tag extends Model
21 protected $fillable = ['name', 'value', 'order'];
22 protected $hidden = ['id', 'entity_id', 'entity_type', 'created_at', 'updated_at'];
25 * Get the entity that this tag belongs to.
27 public function entity(): MorphTo
29 return $this->morphTo('entity');
32 public function jointPermissions(): HasMany
34 return $this->hasMany(JointPermission::class, 'entity_id', 'entity_id')
35 ->whereColumn('tags.entity_type', '=', 'joint_permissions.entity_type');
39 * Get a full URL to start a tag name search for this tag name.
41 public function nameUrl(): string
43 return url('/search?term=%5B' . urlencode($this->name) . '%5D');
47 * Get a full URL to start a tag name and value search for this tag's values.
49 public function valueUrl(): string
51 return url('/search?term=%5B' . urlencode($this->name) . '%3D' . urlencode($this->value) . '%5D');