1 | <?php |
||
7 | class Cover extends Model |
||
8 | { |
||
9 | /** |
||
10 | * Default thumbnail height. |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | public $defaultThumbHeight = 600; |
||
15 | |||
16 | /** |
||
17 | * The attributes that should be visible in arrays. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $visible = ['url', 'cached', 'thumb', 'created', 'modified']; |
||
22 | |||
23 | /** |
||
24 | * The accessors to append to the model's array form. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $appends = ['cached', 'thumb', 'created', 'modified']; |
||
29 | |||
30 | /** |
||
31 | * The attributes that are mass assignable. |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $fillable = ['document_id', 'url']; |
||
36 | |||
37 | /** |
||
38 | * The document the cover belongs to. |
||
39 | * |
||
40 | * @return Document |
||
41 | */ |
||
42 | public function document() |
||
46 | |||
47 | /** |
||
48 | * Returns the URL to the cached image. |
||
49 | * |
||
50 | * @return array |
||
51 | */ |
||
52 | public function getCachedAttribute() |
||
60 | |||
61 | /** |
||
62 | * Get date part of ISO date-time |
||
63 | */ |
||
64 | public function getCreatedAttribute() |
||
68 | |||
69 | /** |
||
70 | * Get date part of ISO date-time |
||
71 | */ |
||
72 | public function getModifiedAttribute() |
||
76 | |||
77 | /** |
||
78 | * Returns the URL to the cached thumb image. |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | public function getThumbAttribute() |
||
90 | |||
91 | /** |
||
92 | * Invalidate cache. |
||
93 | */ |
||
94 | public function invalidateCache() |
||
106 | |||
107 | /** |
||
108 | * Mutuator for the url attribute. Invalidates cache when the paramter changes. |
||
109 | * |
||
110 | * @param $value |
||
111 | */ |
||
112 | public function setUrlAttribute($value) |
||
120 | |||
121 | /** |
||
122 | * Checks if the cover is cached. |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function isCached() |
||
130 | |||
131 | /** |
||
132 | * Cache the cover and create thumbnail. |
||
133 | * |
||
134 | * @throws \ErrorException |
||
135 | */ |
||
136 | public function cache($blob = null) |
||
171 | } |
||
172 |