1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Larafolio\Models; |
4
|
|
|
|
5
|
|
|
use Larafolio\Helpers\Sluggable; |
6
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
7
|
|
|
|
8
|
|
|
class Page extends HasContent |
9
|
|
|
{ |
10
|
|
|
use Sluggable, SoftDeletes; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* The table associated with the model. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $table = 'pages'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The attributes that are mass assignable. |
21
|
|
|
* |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $fillable = [ |
25
|
|
|
'name', 'slug', 'visible', 'order', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Return all visible pages. |
30
|
|
|
* |
31
|
|
|
* @param bool $order If true, order pages by 'order'. |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Support\Collection |
34
|
|
|
*/ |
35
|
|
|
public static function allVisible($order = true) |
36
|
|
|
{ |
37
|
|
|
$query = static::where('visible', true); |
38
|
|
|
|
39
|
|
|
return static::orderAndGroupQuery($query, false, $order); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Return all hidden pages. |
44
|
|
|
* |
45
|
|
|
* @param bool $order If true, order pages by 'order'. |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Support\Collection |
48
|
|
|
*/ |
49
|
|
|
public static function allHidden($order = true) |
50
|
|
|
{ |
51
|
|
|
$query = static::where('visible', false); |
52
|
|
|
|
53
|
|
|
return static::orderAndGroupQuery($query, false, $order); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return all pages ordered by 'order'. |
58
|
|
|
* |
59
|
|
|
* @return \Illuminate\Support\Collection |
60
|
|
|
*/ |
61
|
|
|
public static function allOrdered() |
62
|
|
|
{ |
63
|
|
|
$query = static::query(); |
64
|
|
|
|
65
|
|
|
return static::orderAndGroupQuery($query, false, true); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Get all pages with given block name. |
70
|
|
|
* |
71
|
|
|
* @param string $blockName Name of block. |
72
|
|
|
* |
73
|
|
|
* @return \Illuminate\Support\Collection |
74
|
|
|
*/ |
75
|
|
|
public static function hasBlockNamed($blockName) |
76
|
|
|
{ |
77
|
|
|
return static::hasRelationshipNamed('pages', 'text_blocks', $blockName); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get all pages with given image name. |
82
|
|
|
* |
83
|
|
|
* @param string $imageName Name of image. |
84
|
|
|
* |
85
|
|
|
* @return \Illuminate\Support\Collection |
86
|
|
|
*/ |
87
|
|
|
public static function hasImageNamed($imageName) |
88
|
|
|
{ |
89
|
|
|
return static::hasRelationshipNamed('pages', 'images', $imageName); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Get all pages with given link name. |
94
|
|
|
* |
95
|
|
|
* @param string $linkName Name of link. |
96
|
|
|
* |
97
|
|
|
* @return \Illuminate\Support\Collection |
98
|
|
|
*/ |
99
|
|
|
public static function hasLinkNamed($linkName) |
100
|
|
|
{ |
101
|
|
|
return static::hasRelationshipNamed('pages', 'links', $linkName); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Return the page id. |
106
|
|
|
* |
107
|
|
|
* @return int |
108
|
|
|
*/ |
109
|
|
|
public function id() |
110
|
|
|
{ |
111
|
|
|
return $this->id; |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Return the page name. |
116
|
|
|
* |
117
|
|
|
* @return string |
118
|
|
|
*/ |
119
|
|
|
public function name() |
120
|
|
|
{ |
121
|
|
|
return $this->name; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Return the page slug. |
126
|
|
|
* |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function slug() |
130
|
|
|
{ |
131
|
|
|
return $this->slug; |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Return the page order value. |
136
|
|
|
* |
137
|
|
|
* @return int |
138
|
|
|
*/ |
139
|
|
|
public function order() |
140
|
|
|
{ |
141
|
|
|
return $this->order; |
|
|
|
|
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
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.