ProductAttribute   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mount() 0 12 3
A render() 0 3 1
A updatedSelectedAttributeIds() 0 3 1
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Product;
4
5
use Adminetic\Website\Models\Admin\Attribute;
6
use Livewire\Component;
7
8
class ProductAttribute extends Component
9
{
10
    public $product;
11
    public $attributes;
12
    public $product_attributes = [];
13
    public $selected_attribute_ids = [];
14
    public $selected_attributes;
15
16
    public function mount($product = null)
17
    {
18
        $this->product = $product;
19
        $this->attributes = Attribute::orderBy('position')->get();
20
        if (! is_null($product)) {
21
            $product_attributes = [];
22
            $this->selected_attribute_ids = $product->attributes->pluck('id')->toArray();
23
            $this->updatedSelectedAttributeIds();
24
            foreach ($product->attributes as $attr) {
25
                $product_attributes[$attr->id] = json_decode($attr->pivot->values, true);
26
            }
27
            $this->product_attributes = $product_attributes;
28
        }
29
    }
30
31
    public function updatedSelectedAttributeIds()
32
    {
33
        $this->selected_attributes = Attribute::find($this->selected_attribute_ids);
34
    }
35
36
    public function render()
37
    {
38
        return view('website::livewire.admin.product.product-attribute');
39
    }
40
}
41