Completed
Push — master ( 2d7ca6...a6d5b0 )
by wen
15:16
created

Link::setUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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