1 <?php namespace BookStack\Uploads;
3 use BookStack\Entities\Page;
8 * @property string name
9 * @property string path
10 * @property string extension
11 * @property bool external
13 class Attachment extends Ownable
15 protected $fillable = ['name', 'order'];
18 * Get the downloadable file name for this upload.
19 * @return mixed|string
21 public function getFileName()
23 if (strpos($this->name, '.') !== false) {
26 return $this->name . '.' . $this->extension;
30 * Get the page this file was uploaded to.
31 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
33 public function page()
35 return $this->belongsTo(Page::class, 'uploaded_to');
39 * Get the url of this file.
41 public function getUrl(): string
43 if ($this->external && strpos($this->path, 'http') !== 0) {
46 return url('/attachments/' . $this->id);
50 * Generate a HTML link to this attachment.
52 public function htmlLink(): string
54 return '<a target="_blank" href="'.e($this->getUrl()).'">'.e($this->name).'</a>';
58 * Generate a markdown link to this attachment.
60 public function markdownLink(): string
62 return '['. $this->name .']('. $this->getUrl() .')';