]> BookStack Code Mirror - bookstack/blob - app/File.php
Merge fixes from branch 'v0.12'
[bookstack] / app / File.php
1 <?php namespace BookStack;
2
3
4 class File extends Ownable
5 {
6     protected $fillable = ['name', 'order'];
7
8     /**
9      * Get the downloadable file name for this upload.
10      * @return mixed|string
11      */
12     public function getFileName()
13     {
14         if (str_contains($this->name, '.')) return $this->name;
15         return $this->name . '.' . $this->extension;
16     }
17
18     /**
19      * Get the page this file was uploaded to.
20      * @return Page
21      */
22     public function page()
23     {
24         return $this->belongsTo(Page::class, 'uploaded_to');
25     }
26
27     /**
28      * Get the url of this file.
29      * @return string
30      */
31     public function getUrl()
32     {
33         return baseUrl('/files/' . $this->id);
34     }
35
36 }