]> BookStack Code Mirror - bookstack/blob - app/References/Reference.php
Implemented alternate approach to current joint_permissions
[bookstack] / app / References / Reference.php
1 <?php
2
3 namespace BookStack\References;
4
5 use BookStack\Auth\Permissions\JointPermission;
6 use Illuminate\Database\Eloquent\Model;
7 use Illuminate\Database\Eloquent\Relations\HasMany;
8 use Illuminate\Database\Eloquent\Relations\MorphTo;
9
10 /**
11  * @property int    $from_id
12  * @property string $from_type
13  * @property int    $to_id
14  * @property string $to_type
15  */
16 class Reference extends Model
17 {
18     public $timestamps = false;
19
20     public function from(): MorphTo
21     {
22         return $this->morphTo('from');
23     }
24
25     public function to(): MorphTo
26     {
27         return $this->morphTo('to');
28     }
29
30     public function jointPermissions(): HasMany
31     {
32         return $this->hasMany(JointPermission::class, 'entity_id', 'from_id')
33             ->whereColumn('references.from_type', '=', 'joint_permissions.entity_type');
34     }
35 }