Completed
Push — master ( 77dbd7...6a8ad9 )
by wen
26:38
created

Element::isRelationship()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
4
namespace Sco\Admin\Form\Elements;
5
6
use Illuminate\Database\Eloquent\Model;
7
use JsonSerializable;
8
use Illuminate\Contracts\Support\Arrayable;
9
use Illuminate\Contracts\Support\Jsonable;
10
use Sco\Admin\Contracts\Form\Elements\ElementInterface;
11
use Sco\Admin\Contracts\WithModel;
12
13
abstract class Element implements
14
    ElementInterface,
15
    WithModel,
16
    Arrayable,
17
    Jsonable,
18
    JsonSerializable
19
{
20
    protected $type;
21
22
    protected $name;
23
    protected $title;
24
25
    /**
26
     * @var \Illuminate\Database\Eloquent\Model
27
     */
28
    protected $model;
29
30
    public function __construct($name, $title)
31
    {
32
        $this->name  = $name;
33
        $this->title = $title;
34
    }
35
36
    public function getModel()
37
    {
38
        return $this->model;
39
    }
40
41
    public function setModel(Model $model)
42
    {
43
        $this->model = $model;
44
45
        return $this;
46
    }
47
48
    public function toArray()
49
    {
50
        return [
51
            'key'   => $this->name,
52
            'title' => $this->title,
53
            'type'  => $this->type,
54
        ];
55
    }
56
57
    public function jsonSerialize()
58
    {
59
        return $this->toArray();
60
    }
61
62
    public function toJson($options = 0)
63
    {
64
        return json_encode($this->jsonSerialize(), $options);
65
    }
66
67
    public function __toString()
68
    {
69
        return $this->toJson();
70
    }
71
}
72