1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* App\Guitar. |
9
|
|
|
* |
10
|
|
|
* @property int $id |
11
|
|
|
* @property int $purchase_id |
12
|
|
|
* @property int $rack_id |
13
|
|
|
* @property int $make_id |
14
|
|
|
* @property int $model_id |
15
|
|
|
* @property string $colour |
16
|
|
|
* @property bool $damaged |
17
|
|
|
* @property string $condition |
18
|
|
|
* @property float $price |
19
|
|
|
* @property \Carbon\Carbon $deleted_at |
20
|
|
|
* @property-read \App\Make $make |
21
|
|
|
* @property-read \App\Model $model |
22
|
|
|
* @property-read \App\Rack $rack |
23
|
|
|
* @property-read \App\Purchase $purchase |
24
|
|
|
* @property-read \App\Sale $sale |
25
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereId($value) |
26
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar wherePurchaseId($value) |
27
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereRackId($value) |
28
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereMakeId($value) |
29
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereModelId($value) |
30
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereColour($value) |
31
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereDamaged($value) |
32
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereCondition($value) |
33
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar wherePrice($value) |
34
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar whereDeletedAt($value) |
35
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar sold() |
36
|
|
|
* @method static \Illuminate\Database\Query\Builder|\App\Guitar unsold() |
37
|
|
|
* @mixin \Eloquent |
38
|
|
|
*/ |
39
|
|
|
class Guitar extends Eloquent\Model |
40
|
|
|
{ |
41
|
|
|
use Eloquent\SoftDeletes; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* We do not want any timestamps. |
45
|
|
|
* |
46
|
|
|
* @var bool |
47
|
|
|
*/ |
48
|
|
|
public $timestamps = false; |
49
|
|
|
/** |
50
|
|
|
* @var array |
51
|
|
|
*/ |
52
|
|
|
protected $dates = ['deleted_at']; |
53
|
|
|
/** |
54
|
|
|
* The attributes that are not mass assignable. |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $guarded = []; |
59
|
|
|
|
60
|
7 |
|
public static function boot() |
61
|
|
|
{ |
62
|
7 |
|
parent::boot(); |
63
|
|
|
|
64
|
7 |
|
static::deleting(function (Guitar $guitar) { |
65
|
|
|
$guitar->sale->delete(); |
66
|
7 |
|
}); |
67
|
7 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Sold guitars. |
71
|
|
|
* |
72
|
|
|
* @param $query |
73
|
|
|
* |
74
|
|
|
* @return Eloquent\Builder |
75
|
|
|
*/ |
76
|
1 |
|
public function scopeSold($query) |
77
|
|
|
{ |
78
|
1 |
|
return $query->has('sale'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Unsold Guitars. |
83
|
|
|
* |
84
|
|
|
* @param $query |
85
|
|
|
* |
86
|
|
|
* @return Eloquent\Builder |
87
|
|
|
*/ |
88
|
|
|
public function scopeUnsold($query) |
89
|
|
|
{ |
90
|
|
|
return $query->doesntHave('sale'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Make of the guitar. |
95
|
|
|
* |
96
|
|
|
* @return Eloquent\Relations\BelongsTo |
97
|
|
|
*/ |
98
|
|
|
public function make() |
99
|
|
|
{ |
100
|
|
|
return $this->belongsTo(Make::class); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Model of the guitar. |
105
|
|
|
* |
106
|
|
|
* @return Eloquent\Relations\BelongsTo |
107
|
|
|
*/ |
108
|
|
|
public function model() |
109
|
|
|
{ |
110
|
|
|
return $this->belongsTo(Model::class); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Rack where guitar is stored. |
115
|
|
|
* |
116
|
|
|
* @return Eloquent\Relations\BelongsTo |
117
|
|
|
*/ |
118
|
|
|
public function rack() |
119
|
|
|
{ |
120
|
|
|
return $this->belongsTo(Rack::class); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* The shipment in which the guitar was bought. |
125
|
|
|
* |
126
|
|
|
* @return Eloquent\Relations\BelongsTo |
127
|
|
|
*/ |
128
|
|
|
public function purchase() |
129
|
|
|
{ |
130
|
|
|
return $this->belongsTo(Purchase::class); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Sale record of the guitar. |
135
|
|
|
* |
136
|
|
|
* @return Eloquent\Relations\HasOne |
137
|
|
|
*/ |
138
|
1 |
|
public function sale() |
139
|
|
|
{ |
140
|
1 |
|
return $this->hasOne(Sale::class); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Status of the guitar. |
145
|
|
|
* @return bool |
146
|
|
|
*/ |
147
|
|
|
public function isSold() |
148
|
|
|
{ |
149
|
|
|
return ! is_null($this->sale); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|