ProductVariant::attribute()   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
8
class ProductVariant extends Model
9
{
10
    /**
11
     * Table name of the model
12
     * 
13
     * @var string
14
     */
15
    protected $table = 'product_variations';
16
17
    /**
18
     * Disable timestamp
19
     * 
20
     * @var bool
21
     */
22
    public $timestamps = false;
23
24
    /**
25
     * Fields that can be mass assigned
26
     * 
27
     * @var array
28
     */
29
    protected $fillable = [
30
        'product_id', 'product_sku_id', 'product_attribute_id',
31
        'product_attribute_value_id'
32
    ];
33
34
    /**
35
     * Protected fields during mass assigned
36
     * 
37
     * @var array
38
     */
39
    protected $guarded = [
40
        'id'
41
    ];
42
43
    /**
44
     * Relation of the variation to the product sku
45
     * 
46
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
47
     */
48
    public function productSku(): BelongsTo
49
	{
50
		return $this->belongsTo('Ronmrcdo\Inventory\Models\ProductSku', 'product_sku_id');
51
	}
52
    
53
    /**
54
     * Relation of the variation to the product
55
     * 
56
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
57
     */
58
    public function product(): BelongsTo
59
    {
60
        return $this->belongsTo(config('laravel-inventory.product'));
61
    }
62
63
    /**
64
     * Relation of the variation product to the attribute
65
     * 
66
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
67
     */
68
    public function attribute(): BelongsTo
69
    {
70
        return $this->belongsTo('Ronmrcdo\Inventory\Models\Attribute', 'product_attribute_id');
71
    }
72
73
    /**
74
     * Relation of the variation product to the attribute option
75
     * 
76
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
77
     */
78
    public function option(): BelongsTo
79
    {
80
        return $this->belongsTo('Ronmrcdo\Inventory\Models\AttributeValue', 'product_attribute_value_id');
81
    }
82
}
83