1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larafolio\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
|
7
|
|
|
class Image extends Model |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* The table associated with the model. |
11
|
|
|
* |
12
|
|
|
* @var string |
13
|
|
|
*/ |
14
|
|
|
protected $table = 'images'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The attributes that are mass assignable. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected $fillable = ['path', 'name', 'caption', 'alt']; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Get route for thumbnail version of image. |
25
|
|
|
* |
26
|
|
|
* @return string |
27
|
|
|
*/ |
28
|
|
|
public function thumbnail() |
29
|
|
|
{ |
30
|
|
|
return $this->imageRoute('thumbnail'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get route for small version of image. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public function small() |
39
|
|
|
{ |
40
|
|
|
return $this->imageRoute('small'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get route for medium version of image. |
45
|
|
|
* |
46
|
|
|
* @return string |
47
|
|
|
*/ |
48
|
|
|
public function medium() |
49
|
|
|
{ |
50
|
|
|
return $this->imageRoute('medium'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get route for full size version of image. |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function full() |
59
|
|
|
{ |
60
|
|
|
return $this->imageRoute('full'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Get route for given template image. |
65
|
|
|
* |
66
|
|
|
* @param string $templateName Name of image cache template. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function imageRoute($templateName) |
71
|
|
|
{ |
72
|
|
|
return "/manager/images/{$templateName}/{$this->fileName()}"; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the file name of the image. |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
public function fileName() |
81
|
|
|
{ |
82
|
|
|
return collect(explode('/', $this->path))->last(); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Return image properties to be passed to js. |
87
|
|
|
* |
88
|
|
|
* @return array |
89
|
|
|
*/ |
90
|
|
|
public function generateProps() |
91
|
|
|
{ |
92
|
|
|
return [ |
93
|
|
|
'thumbnail' => $this->thumbnail(), |
94
|
|
|
'small' => $this->small(), |
95
|
|
|
'medium' => $this->medium(), |
96
|
|
|
'full' => $this->full(), |
97
|
|
|
'name' => $this->name, |
|
|
|
|
98
|
|
|
'caption' => $this->caption, |
|
|
|
|
99
|
|
|
'alt' => $this->alt, |
|
|
|
|
100
|
|
|
'id' => $this->id, |
|
|
|
|
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.