-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffee.php
More file actions
113 lines (99 loc) · 2.51 KB
/
Copy pathCoffee.php
File metadata and controls
113 lines (99 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
namespace App\Models;
class Coffee extends SuperModel
{
protected $fillable = ['name',
'green_bean_id',
'short_name',
'slug',
'coffee_desc',
'short_desc',
'blend',
'roast_type_id',
'price_1kg',
'price_250g',
'in_stock',
'stock_weight',
'stock_kg_bags',
'stock_g_bags',
'last_roast_date',
'new_bean',
'new_bean_date',
'sticker_id',
'active',
'user_id'];
protected $dates = ['last_roast_date', 'new_bean_date'];
protected $casts = [
'blend' => 'boolean',
'in_stock' => 'boolean',
'active' => 'boolean',
'new_bean' => 'boolean'
];
/**
* Get the user that created/updated the coffee.
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* The origin this coffee belongs to
*/
/*public function origin()
{
return $this->belongsTo(Origin::class);
}*/
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
* Order items for the product
*/
public function orderItem()
{
return $this->hasMany(OrderItem::class);
}
public function roast()
{
return $this->hasMany(Roast::class);
}
public function blendCoffees()
{
return $this->belongsToMany(Coffee::class, 'blend_coffee', 'blend_id', 'coffee_id')->withPivot('percent')->orderBy('name');
}
public function roastType()
{
return $this->belongsTo(RoastType::class);
}
public function sticker()
{
return $this->belongsTo(Sticker::class);
}
public function stock()
{
return $this->hasOne(Stock::class);
}
public function dispacth()
{
return $this->hasMany(Dispatch::class);
}
public function greenBean()
{
return $this->belongsTo(GreenBean::class);
}
/**
* Gets a number and returns kg or g
* @param type $weight
*/
public function weight_text($weight)
{
if($weight == 0)
{
return $weight;
} elseif($weight < 1000) {
return $weight . 'g';
} else {
$weight = $weight / 1000;
return $weight . 'kg';
}
}
}