ProductSku::product()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Ronmrcdo\Inventory\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\Relations\HasMany;
8
9
class ProductSku extends Model
10
{
11
    /**
12
     * Table name of the model
13
     * 
14
     * @var string
15
     */
16
    protected $table = 'product_skus';
17
18
    /**
19
     * Disable the timestamp on model creation
20
     * 
21
     * @var bool
22
     */
23
    public $timestamps = false;
24
25
    /**
26
     * Fields that can be mass assigned
27
     * 
28
     * @var array
29
     */
30
    protected $fillable = [
31
        'product_id', 'code', 'price', 'cost'
32
    ];
33
34
    /**
35
     * Fields that are guarded during mass assign
36
     * 
37
     * @var array
38
     */
39
    protected $guarded = [
40
        'id'
41
    ];
42
43
    /**
44
     * Relation to the product
45
     * 
46
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
47
     */
48
    public function product(): BelongsTo
49
    {
50
         return $this->belongsTo(config('laravel-inventory.product'));
51
    }
52
53
    /**
54
     * Product Variant
55
     * 
56
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
57
     */
58
    public function variant(): HasMany
59
    {
60
        return $this->hasMany('Ronmrcdo\Inventory\Models\ProductVariant', 'product_sku_id');
61
    }
62
63
    /**
64
     * Product sku has many stocks
65
     * 
66
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
67
     */
68
    public function stocks(): HasMany
69
    {
70
        return $this->hasMany('Ronmrcdo\Inventory\Models\InventoryStock');
71
    }
72
}
73