-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreenBean.php
More file actions
70 lines (58 loc) · 1.63 KB
/
Copy pathGreenBean.php
File metadata and controls
70 lines (58 loc) · 1.63 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
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class GreenBean extends SuperModel
{
use SoftDeletes;
protected $table = 'green_beans';
protected $dates = ['deleted_at'];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'country_id',
'name',
'stock',
'low_stock_warn'
];
public function country()
{
return $this->belongsTo(Country::class);
}
public function suppliers()
{
return $this->belongsToMany(Supplier::class)->withPivot('bag_size');
}
public function coffees()
{
return $this->hasMany(Coffee::class);
}
public function activeCoffees()
{
return $this->coffees->where('active', 1)->get();
}
//Get soft deleted model
/**
* Retrieve the model for a bound value.
*
* @param mixed $value
* @param string|null $field
* @return \Illuminate\Database\Eloquent\Model|null
*/
/*public function resolveRouteBinding($value, $field = null)
{
// If no field was given, use the primary key
if ($field === null) {
$field = $this->getRouteKeyName();
}
// Apply where clause
$query = $this->where($field, $value);
// Conditionally remove the softdelete scope to allow seeing soft-deleted records
$query->withoutGlobalScope(SoftDeletingScope::class);
// Find the first record, or abort
return $query->firstOrFail();
}*/
}