2016-10-09 13:58:22 -04:00
|
|
|
<?php namespace BookStack;
|
|
|
|
|
|
|
|
|
2016-11-12 09:12:26 -05:00
|
|
|
class Attachment extends Ownable
|
2016-10-09 13:58:22 -04:00
|
|
|
{
|
|
|
|
protected $fillable = ['name', 'order'];
|
|
|
|
|
2016-10-23 08:36:45 -04: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-09 13:58:22 -04:00
|
|
|
/**
|
|
|
|
* Get the page this file was uploaded to.
|
2016-10-10 15:30:27 -04:00
|
|
|
* @return Page
|
2016-10-09 13:58:22 -04:00
|
|
|
*/
|
|
|
|
public function page()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Page::class, 'uploaded_to');
|
|
|
|
}
|
|
|
|
|
2016-10-10 15:30:27 -04:00
|
|
|
/**
|
|
|
|
* Get the url of this file.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getUrl()
|
|
|
|
{
|
2016-11-12 09:12:26 -05:00
|
|
|
return baseUrl('/attachments/' . $this->id);
|
2016-10-10 15:30:27 -04:00
|
|
|
}
|
2016-10-09 13:58:22 -04:00
|
|
|
|
|
|
|
}
|