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