1 | <?php |
||
30 | class Rack extends Eloquent\Model |
||
31 | { |
||
32 | use Eloquent\SoftDeletes; |
||
33 | |||
34 | /** |
||
35 | * We do not want any timestamps. |
||
36 | * |
||
37 | * @var bool |
||
38 | */ |
||
39 | public $timestamps = false; |
||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $dates = ['deleted_at']; |
||
44 | /** |
||
45 | * The attributes that are not mass assignable. |
||
46 | * |
||
47 | * @var array |
||
48 | */ |
||
49 | protected $fillable = ['name', 'capacity', 'make_id', 'warehouse_id']; |
||
50 | |||
51 | 10 | public static function boot() |
|
52 | { |
||
53 | 10 | parent::boot(); |
|
54 | |||
55 | 10 | static::deleting(function (Rack $rack) { |
|
56 | 2 | $rack->guitars()->delete(); |
|
57 | 10 | }); |
|
58 | 10 | } |
|
59 | |||
60 | /** |
||
61 | * Warehouse the rack is in. |
||
62 | * |
||
63 | * @return Eloquent\Relations\BelongsTo |
||
64 | */ |
||
65 | public function warehouse() |
||
69 | |||
70 | /** |
||
71 | * Number of used rack space. |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | public function getUsedAttribute() |
||
79 | |||
80 | /** |
||
81 | * Guitars in the rack. |
||
82 | * |
||
83 | * @return Eloquent\Relations\HasMany |
||
84 | */ |
||
85 | 2 | public function guitars() |
|
86 | { |
||
87 | 2 | return $this->hasMany(Guitar::class); |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * Usage of the rack. |
||
92 | * |
||
93 | * @return float |
||
94 | */ |
||
95 | public function getUsageAttribute() |
||
99 | |||
100 | /** |
||
101 | * Is the rack full? |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function isFull() |
||
109 | |||
110 | /** |
||
111 | * Guitar make this rack can hold. |
||
112 | * |
||
113 | * @return Eloquent\Relations\BelongsTo |
||
114 | */ |
||
115 | public function make() |
||
119 | } |
||
120 |