]> BookStack Code Mirror - bookstack/blob - app/Uploads/Image.php
Apply fixes from StyleCI
[bookstack] / app / Uploads / Image.php
1 <?php
2
3 namespace BookStack\Uploads;
4
5 use BookStack\Entities\Models\Page;
6 use BookStack\Model;
7 use BookStack\Traits\HasCreatorAndUpdater;
8
9 /**
10  * @property int    $id
11  * @property string $name
12  * @property string $url
13  * @property string $path
14  * @property string $type
15  * @property int    $uploaded_to
16  * @property int    $created_by
17  * @property int    $updated_by
18  */
19 class Image extends Model
20 {
21     use HasCreatorAndUpdater;
22
23     protected $fillable = ['name'];
24     protected $hidden = [];
25
26     /**
27      * Get a thumbnail for this image.
28      *
29      * @throws \Exception
30      */
31     public function getThumb(int $width, int $height, bool $keepRatio = false): string
32     {
33         return app()->make(ImageService::class)->getThumbnail($this, $width, $height, $keepRatio);
34     }
35
36     /**
37      * Get the page this image has been uploaded to.
38      * Only applicable to gallery or drawio image types.
39      */
40     public function getPage(): ?Page
41     {
42         return $this->belongsTo(Page::class, 'uploaded_to')->first();
43     }
44 }