]> BookStack Code Mirror - bookstack/blob - app/Actions/Tag.php
Added force option for update-url command
[bookstack] / app / Actions / Tag.php
1 <?php
2
3 namespace BookStack\Actions;
4
5 use BookStack\Auth\Permissions\JointPermission;
6 use BookStack\Model;
7 use Illuminate\Database\Eloquent\Factories\HasFactory;
8 use Illuminate\Database\Eloquent\Relations\HasMany;
9 use Illuminate\Database\Eloquent\Relations\MorphTo;
10
11 /**
12  * @property int    $id
13  * @property string $name
14  * @property string $value
15  * @property int    $order
16  */
17 class Tag extends Model
18 {
19     use HasFactory;
20
21     protected $fillable = ['name', 'value', 'order'];
22     protected $hidden = ['id', 'entity_id', 'entity_type', 'created_at', 'updated_at'];
23
24     /**
25      * Get the entity that this tag belongs to.
26      */
27     public function entity(): MorphTo
28     {
29         return $this->morphTo('entity');
30     }
31
32     public function jointPermissions(): HasMany
33     {
34         return $this->hasMany(JointPermission::class, 'entity_id', 'entity_id')
35             ->whereColumn('tags.entity_type', '=', 'joint_permissions.entity_type');
36     }
37
38     /**
39      * Get a full URL to start a tag name search for this tag name.
40      */
41     public function nameUrl(): string
42     {
43         return url('/search?term=%5B' . urlencode($this->name) . '%5D');
44     }
45
46     /**
47      * Get a full URL to start a tag name and value search for this tag's values.
48      */
49     public function valueUrl(): string
50     {
51         return url('/search?term=%5B' . urlencode($this->name) . '%3D' . urlencode($this->value) . '%5D');
52     }
53 }