2022-08-17 21:39:53 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\References;
|
|
|
|
|
2023-05-18 00:56:55 +08:00
|
|
|
use BookStack\Permissions\Models\JointPermission;
|
2022-08-17 21:39:53 +08:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-01-24 22:55:34 +08:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2022-08-17 21:39:53 +08:00
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
|
|
|
|
/**
|
2022-08-30 00:46:41 +08:00
|
|
|
* @property int $from_id
|
2022-08-17 21:39:53 +08:00
|
|
|
* @property string $from_type
|
2022-08-30 00:46:41 +08:00
|
|
|
* @property int $to_id
|
2022-08-17 21:39:53 +08:00
|
|
|
* @property string $to_type
|
|
|
|
*/
|
|
|
|
class Reference extends Model
|
|
|
|
{
|
2022-08-18 00:37:27 +08:00
|
|
|
public $timestamps = false;
|
|
|
|
|
2022-08-17 21:39:53 +08:00
|
|
|
public function from(): MorphTo
|
|
|
|
{
|
|
|
|
return $this->morphTo('from');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function to(): MorphTo
|
|
|
|
{
|
|
|
|
return $this->morphTo('to');
|
|
|
|
}
|
2023-01-24 22:55:34 +08:00
|
|
|
|
|
|
|
public function jointPermissions(): HasMany
|
|
|
|
{
|
|
|
|
return $this->hasMany(JointPermission::class, 'entity_id', 'from_id')
|
|
|
|
->whereColumn('references.from_type', '=', 'joint_permissions.entity_type');
|
|
|
|
}
|
2022-08-17 21:39:53 +08:00
|
|
|
}
|