2022-08-17 09:39:53 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\References;
|
|
|
|
|
2023-01-24 09:55:34 -05:00
|
|
|
use BookStack\Auth\Permissions\JointPermission;
|
2022-08-17 09:39:53 -04:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-01-24 09:55:34 -05:00
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2022-08-17 09:39:53 -04:00
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
|
|
|
|
|
|
|
/**
|
2022-08-29 12:46:41 -04:00
|
|
|
* @property int $from_id
|
2022-08-17 09:39:53 -04:00
|
|
|
* @property string $from_type
|
2022-08-29 12:46:41 -04:00
|
|
|
* @property int $to_id
|
2022-08-17 09:39:53 -04:00
|
|
|
* @property string $to_type
|
|
|
|
*/
|
|
|
|
class Reference extends Model
|
|
|
|
{
|
2022-08-17 12:37:27 -04:00
|
|
|
public $timestamps = false;
|
|
|
|
|
2022-08-17 09:39:53 -04:00
|
|
|
public function from(): MorphTo
|
|
|
|
{
|
|
|
|
return $this->morphTo('from');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function to(): MorphTo
|
|
|
|
{
|
|
|
|
return $this->morphTo('to');
|
|
|
|
}
|
2023-01-24 09:55:34 -05: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 09:39:53 -04:00
|
|
|
}
|