2016-10-10 01:58:22 +08:00
|
|
|
<?php namespace BookStack;
|
|
|
|
|
|
|
|
|
2016-11-12 22:12:26 +08:00
|
|
|
class Attachment extends Ownable
|
2016-10-10 01:58:22 +08:00
|
|
|
{
|
|
|
|
protected $fillable = ['name', 'order'];
|
|
|
|
|
2016-10-23 20:36:45 +08:00
|
|
|
/**
|
|
|
|
* Get the downloadable file name for this upload.
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
|
|
|
public function getFileName()
|
|
|
|
{
|
|
|
|
if (str_contains($this->name, '.')) return $this->name;
|
|
|
|
return $this->name . '.' . $this->extension;
|
|
|
|
}
|
|
|
|
|
2016-10-10 01:58:22 +08:00
|
|
|
/**
|
|
|
|
* Get the page this file was uploaded to.
|
2016-10-11 03:30:27 +08:00
|
|
|
* @return Page
|
2016-10-10 01:58:22 +08:00
|
|
|
*/
|
|
|
|
public function page()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Page::class, 'uploaded_to');
|
|
|
|
}
|
|
|
|
|
2016-10-11 03:30:27 +08:00
|
|
|
/**
|
|
|
|
* Get the url of this file.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUrl()
|
|
|
|
{
|
2016-11-12 22:12:26 +08:00
|
|
|
return baseUrl('/attachments/' . $this->id);
|
2016-10-11 03:30:27 +08:00
|
|
|
}
|
2016-10-10 01:58:22 +08:00
|
|
|
|
|
|
|
}
|