Completed
Push — master ( ad47fd...d32456 )
by wen
11:12
created

Image::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
4
namespace Sco\Admin\View\Columns;
5
6
class Image extends Column
7
{
8
    protected $template = '<img v-viewer="column.options" :width="value.width" :src="value.image" v-if="value.image">';
9
10
    /**
11
     * @var string
12
     */
13
    protected $imageWidth = '80px';
14
15
    protected $disk;
16
17
    /**
18
     * @return string
19
     */
20
    public function getImageWidth()
21
    {
22
        return $this->imageWidth;
23
    }
24
25
    /**
26
     * @param string $width
27
     *
28
     * @return $this
29
     */
30
    public function setImageWidth($width)
31
    {
32
        $this->imageWidth = $width;
33
34
        return $this;
35
    }
36
37
    public function getDisk()
38
    {
39
        if ($this->disk) {
40
            return $this->disk;
41
        }
42
43
        return config('admin.upload.disk', 'public');
44
    }
45
46
    public function setDisk($value)
47
    {
48
        $this->disk = $value;
49
50
        return $this;
51
    }
52
53
    public function getValue()
54
    {
55
        $value = parent::getValue();
56
        if (!empty($value) && (strpos($value, '://') === false)) {
57
            if (($disk = $this->getDisk())) {
58
                $value = \Storage::disk($disk)->url($value);
59
            } else {
60
                $value = asset($value);
61
            }
62
        }
63
64
        return [
65
            'image' => $value,
66
            'width' => $this->getImageWidth(),
67
        ];
68
    }
69
70
    public function toArray()
71
    {
72
        return parent::toArray() + [
73
                'options' => [
74
                    'toolbar' => false,
75
                    'navbar'  => false,
76
                ],
77
            ];
78
    }
79
}
80