1 | <?php |
||
12 | class Vacancy extends EloquentModel |
||
13 | { |
||
14 | /** |
||
15 | * The attributes that are mass assignable. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $fillable = [ |
||
20 | 'business_id', |
||
21 | 'service_id', |
||
22 | 'humanresource_id', |
||
23 | 'date', |
||
24 | 'start_at', |
||
25 | 'finish_at', |
||
26 | 'capacity', |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * The attributes that aren't mass assignable. |
||
31 | * |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $guarded = ['id']; |
||
35 | |||
36 | /** |
||
37 | * The attributes that should be mutated to dates. |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $dates = ['start_at', 'finish_at']; |
||
42 | |||
43 | /////////////////// |
||
44 | // Relationships // |
||
45 | /////////////////// |
||
46 | |||
47 | /** |
||
48 | * belongs to Business. |
||
49 | * |
||
50 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Vacancy belongs to Business query |
||
51 | */ |
||
52 | 16 | public function business() |
|
53 | { |
||
54 | 16 | return $this->belongsTo(Business::class); |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * for Service. |
||
59 | * |
||
60 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Vacancy is for providing Service query |
||
61 | */ |
||
62 | 26 | public function service() |
|
63 | { |
||
64 | 26 | return $this->belongsTo(Service::class); |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Humanresource. |
||
69 | * |
||
70 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
71 | */ |
||
72 | 18 | public function humanresource() |
|
76 | |||
77 | /** |
||
78 | * holds many Appointments. |
||
79 | * |
||
80 | * @return \Illuminate\Database\Eloquent\Relations\HasMany Relationship Vacancy belongs to Business query |
||
81 | */ |
||
82 | 10 | public function appointments() |
|
86 | |||
87 | /** |
||
88 | * Humanresource Slug. |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | public function humanresourceSlug() |
||
101 | |||
102 | //////////// |
||
103 | // Scopes // |
||
104 | //////////// |
||
105 | |||
106 | /** |
||
107 | * Scope For Date. |
||
108 | * |
||
109 | * @param Illuminate\Database\Query $query |
||
110 | * @param Carbon $date Date of inquiry |
||
111 | * |
||
112 | * @return Illuminate\Database\Query Scoped query |
||
113 | */ |
||
114 | 6 | public function scopeForDate($query, Carbon $date) |
|
118 | |||
119 | /** |
||
120 | * Scope For DateTime. |
||
121 | * |
||
122 | * @param Illuminate\Database\Query $query |
||
123 | * @param Carbon $datetime Date and Time of inquiry |
||
124 | * |
||
125 | * @return Illuminate\Database\Query Scoped query |
||
126 | */ |
||
127 | 6 | public function scopeForDateTime($query, Carbon $datetime) |
|
132 | |||
133 | /** |
||
134 | * Scope only Future. |
||
135 | * |
||
136 | * @param Illuminate\Database\Query $query |
||
137 | * |
||
138 | * @return Illuminate\Database\Query Scoped query |
||
139 | */ |
||
140 | 1 | public function scopeFuture($query) |
|
144 | |||
145 | /** |
||
146 | * Scope For Service. |
||
147 | * |
||
148 | * @param Illuminate\Database\Query $query |
||
149 | * @param int serviceId $service Inquired Service to filter |
||
150 | * |
||
151 | * @return Illuminate\Database\Query Scoped query |
||
152 | */ |
||
153 | 14 | public function scopeForService($query, $serviceId) |
|
157 | |||
158 | ///////////////////// |
||
159 | // Soft Attributes // |
||
160 | ///////////////////// |
||
161 | |||
162 | /** |
||
163 | * is Holding Any Appointment for given User. |
||
164 | * |
||
165 | * ToDo: Remove from here as needs knowledge from User |
||
166 | * |
||
167 | * @param int $userId User to check belonging Appointments |
||
168 | * |
||
169 | * @return bool Vacancy holds at least one Appointment of User |
||
170 | */ |
||
171 | 2 | public function isHoldingAnyFor($userId) |
|
184 | |||
185 | /** |
||
186 | * is Full. |
||
187 | * |
||
188 | * @return bool Vacancy is fully booked |
||
189 | */ |
||
190 | # public function isFull() |
||
191 | # { |
||
192 | # return $this->getFreeSlotsCount() <= 0; |
||
193 | # } |
||
194 | |||
195 | /** |
||
196 | * get free slots count. |
||
197 | * |
||
198 | * @return int Count Capacity minus Used |
||
199 | */ |
||
200 | # public function getFreeSlotsCount() |
||
201 | # { |
||
202 | # $count = $this->appointments()->active()->count(); |
||
203 | # |
||
204 | # return $this->capacity - $count; |
||
205 | # } |
||
206 | |||
207 | /** |
||
208 | * get capacity. |
||
209 | * |
||
210 | * @return int Capacity of the vacancy (in appointment instances) |
||
211 | */ |
||
212 | 17 | public function getCapacityAttribute() |
|
220 | |||
221 | /** |
||
222 | * has Room. |
||
223 | * |
||
224 | * @return bool There is more capacity than used |
||
225 | */ |
||
226 | 4 | public function hasRoom() |
|
230 | |||
231 | /** |
||
232 | * has Room between time. |
||
233 | * |
||
234 | * @return bool There is more capacity than used |
||
235 | */ |
||
236 | 4 | public function hasRoomBetween(Carbon $startAt, Carbon $finishAt) |
|
246 | |||
247 | /** |
||
248 | * Get available capacity between time. |
||
249 | * |
||
250 | * @return int Available capacity |
||
251 | */ |
||
252 | 8 | public function getAvailableCapacityBetween(Carbon $startAt, Carbon $finishAt) |
|
268 | } |
||
269 |
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.