2018-09-25 13:30:50 +02:00
|
|
|
<?php namespace BookStack\Uploads;
|
|
|
|
|
|
|
|
use BookStack\Entities\Page;
|
|
|
|
use BookStack\Ownable;
|
2016-10-09 19:58:22 +02:00
|
|
|
|
2016-11-12 15:12:26 +01:00
|
|
|
class Attachment extends Ownable
|
2016-10-09 19:58:22 +02:00
|
|
|
{
|
|
|
|
protected $fillable = ['name', 'order'];
|
|
|
|
|
2016-10-23 14:36:45 +02:00
|
|
|
/**
|
|
|
|
* Get the downloadable file name for this upload.
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public function getFileName()
|
|
|
|
{
|
2019-09-14 00:58:40 +02:00
|
|
|
if (strpos($this->name, '.') !== false) {
|
2018-01-28 17:58:52 +01:00
|
|
|
return $this->name;
|
|
|
|
}
|
2016-10-23 14:36:45 +02:00
|
|
|
return $this->name . '.' . $this->extension;
|
|
|
|
}
|
|
|
|
|
2016-10-09 19:58:22 +02:00
|
|
|
/**
|
|
|
|
* Get the page this file was uploaded to.
|
2018-09-25 19:00:40 +02:00
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2016-10-09 19:58:22 +02:00
|
|
|
*/
|
|
|
|
public function page()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Page::class, 'uploaded_to');
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:30:27 +02:00
|
|
|
/**
|
|
|
|
* Get the url of this file.
|
|
|
|
*/
|
2020-06-30 23:12:45 +02:00
|
|
|
public function getUrl(): string
|
2016-10-10 21:30:27 +02:00
|
|
|
{
|
2018-05-20 12:06:10 +02:00
|
|
|
if ($this->external && strpos($this->path, 'http') !== 0) {
|
|
|
|
return $this->path;
|
|
|
|
}
|
2019-08-04 15:26:39 +02:00
|
|
|
return url('/attachments/' . $this->id);
|
2016-10-10 21:30:27 +02:00
|
|
|
}
|
2016-10-09 19:58:22 +02:00
|
|
|
}
|