3 namespace BookStack\Uploads;
5 use BookStack\Auth\Permissions\JointPermission;
6 use BookStack\Entities\Models\Page;
8 use BookStack\Traits\HasCreatorAndUpdater;
9 use Illuminate\Database\Eloquent\Factories\HasFactory;
10 use Illuminate\Database\Eloquent\Relations\HasMany;
14 * @property string $name
15 * @property string $url
16 * @property string $path
17 * @property string $type
18 * @property int $uploaded_to
19 * @property int $created_by
20 * @property int $updated_by
22 class Image extends Model
25 use HasCreatorAndUpdater;
27 protected $fillable = ['name'];
28 protected $hidden = [];
30 public function jointPermissions(): HasMany
32 return $this->hasMany(JointPermission::class, 'entity_id', 'uploaded_to')
33 ->where('joint_permissions.entity_type', '=', 'page');
37 * Get a thumbnail for this image.
41 public function getThumb(int $width, int $height, bool $keepRatio = false): string
43 return app()->make(ImageService::class)->getThumbnail($this, $width, $height, $keepRatio);
47 * Get the page this image has been uploaded to.
48 * Only applicable to gallery or drawio image types.
50 public function getPage(): ?Page
52 return $this->belongsTo(Page::class, 'uploaded_to')->first();