Completed
Push — master ( 1885f1...3cadef )
by wen
02:55
created

Link::getUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
4
namespace Sco\Admin\View\Columns;
5
6
class Link extends Column
7
{
8
    protected $template = '<router-link to="value.url">{{value.title}}</router-link>';
9
10
    private $url;
11
12
    public function getUrl()
13
    {
14
        if ($this->url) {
15
            return $this->url;
16
        }
17
        $model = app('admin.components')->get(get_class($this->getModel()))->getName();
18
        $id = $this->getModel()->getKey();
19
        return route('admin.model.edit', [$model, $id]);
20
    }
21
22
    public function setUrl($value)
23
    {
24
        $this->url = $value;
25
26
        return $this;
27
    }
28
29
    public function toArray()
30
    {
31
        return parent::toArray() + [
32
                'value' => [
33
                    'url'   => $this->getUrl(),
34
                    'title' => $this->getModelValue(),
35
                ],
36
            ];
37
    }
38
}
39