]> BookStack Code Mirror - bookstack/blob - app/PageRevision.php
Merge pull request #3 from OsmosysSoftware/revert-1-issue-181
[bookstack] / app / PageRevision.php
1 <?php namespace BookStack;
2
3
4 class PageRevision extends Model
5 {
6     protected $fillable = ['name', 'html', 'text', 'markdown', 'summary'];
7
8     /**
9      * Get the user that created the page revision
10      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
11      */
12     public function createdBy()
13     {
14         return $this->belongsTo(User::class, 'created_by');
15     }
16
17     /**
18      * Get the page this revision originates from.
19      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
20      */
21     public function page()
22     {
23         return $this->belongsTo(Page::class);
24     }
25
26     /**
27      * Get the url for this revision.
28      * @param null|string $path
29      * @return string
30      */
31     public function getUrl($path = null)
32     {
33         $url = $this->page->getUrl() . '/revisions/' . $this->id;
34         if ($path) return $url . '/' . trim($path, '/');
35         return $url;
36     }
37
38     /**
39      * Get the previous revision for the same page if existing
40      * @return \BookStack\PageRevision|null
41      */
42     public function getPrevious()
43     {
44         if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) {
45             return static::find($id);
46         }
47         return null;
48     }
49
50 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.