|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model as EloquentModel; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @property int $id |
|
9
|
|
|
* @property int $business_id |
|
10
|
|
|
* @property Timegridio\Concierge\Models\Business $business |
|
11
|
|
|
* @property string $name |
|
12
|
|
|
* @property string $slug |
|
13
|
|
|
* @property string $description |
|
14
|
|
|
* @property string $prerequisites |
|
15
|
|
|
* @property int $duration |
|
16
|
|
|
* @property int $type_id |
|
17
|
|
|
* @property string $color |
|
18
|
|
|
*/ |
|
19
|
|
|
class Service extends EloquentModel |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* The attributes that are mass assignable. |
|
23
|
|
|
* |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $fillable = [ |
|
27
|
|
|
'name', |
|
28
|
|
|
'business_id', |
|
29
|
|
|
'description', |
|
30
|
|
|
'prerequisites', |
|
31
|
|
|
'duration', |
|
32
|
|
|
'type_id', |
|
33
|
|
|
'color' |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The attributes that aren't mass assignable. |
|
38
|
|
|
* |
|
39
|
|
|
* @var array |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $guarded = ['id', 'slug']; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Belongs to service type. |
|
45
|
|
|
* |
|
46
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Service belongs to type query |
|
47
|
|
|
*/ |
|
48
|
3 |
|
public function type() |
|
49
|
|
|
{ |
|
50
|
3 |
|
return $this->belongsTo(ServiceType::class); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get service type name. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
2 |
|
public function getTypeNameAttribute() |
|
59
|
|
|
{ |
|
60
|
2 |
|
if ($this->type) { |
|
|
|
|
|
|
61
|
1 |
|
return $this->type->name; |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
1 |
|
return ''; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* belongs to Business. |
|
69
|
|
|
* |
|
70
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo Relationship Service belongs to Business query |
|
71
|
|
|
*/ |
|
72
|
3 |
|
public function business() |
|
73
|
|
|
{ |
|
74
|
3 |
|
return $this->belongsTo(Business::class); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* TODO: Check slug setting can be moved to a more proper place. |
|
79
|
|
|
* |
|
80
|
|
|
* Save the model to the database. |
|
81
|
|
|
* |
|
82
|
|
|
* @param array $options |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
75 |
|
public function save(array $options = []) |
|
87
|
|
|
{ |
|
88
|
75 |
|
$this->attributes['slug'] = str_slug($this->attributes['name']); |
|
89
|
|
|
|
|
90
|
75 |
|
return parent::save($options); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
////////////// |
|
94
|
|
|
// Mutators // |
|
95
|
|
|
////////////// |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* set Duration Attribute. |
|
99
|
|
|
* |
|
100
|
|
|
* @param int $duration |
|
101
|
|
|
*/ |
|
102
|
75 |
|
public function setDurationAttribute($duration) |
|
103
|
|
|
{ |
|
104
|
75 |
|
return $this->attributes['duration'] = $duration ? intval($duration) : null; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
//////////// |
|
108
|
|
|
// Scopes // |
|
109
|
|
|
//////////// |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Scope Slug. |
|
113
|
|
|
* |
|
114
|
|
|
* @param Illuminate\Database\Query $query |
|
115
|
|
|
* @param string $slug Slug of the desired Service |
|
116
|
|
|
* |
|
117
|
|
|
* @return Illuminate\Database\Query Scoped query |
|
118
|
|
|
*/ |
|
119
|
1 |
|
public function scopeSlug($query, $slug) |
|
120
|
|
|
{ |
|
121
|
1 |
|
return $query->where('slug', '=', $slug)->get(); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
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@propertyannotation 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.