Total Complexity | 9 |
Total Lines | 65 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | class Group extends \Illuminate\Support\Collection |
||
6 | { |
||
7 | /** |
||
8 | * @var \Illuminate\Database\Eloquent\Model |
||
9 | */ |
||
10 | protected $model; |
||
11 | |||
12 | /** |
||
13 | * @var string|callable |
||
14 | */ |
||
15 | protected $label; |
||
16 | |||
17 | protected $primary; |
||
18 | |||
19 | public function __construct(\Illuminate\Database\Eloquent\Model $model = null, $items = []) |
||
20 | { |
||
21 | $this->model = $model; |
||
22 | |||
23 | parent::__construct($items); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @return \Illuminate\Database\Eloquent\Model |
||
28 | */ |
||
29 | public function getModel() |
||
30 | { |
||
31 | return $this->model; |
||
32 | } |
||
33 | |||
34 | public function getPrimary() |
||
35 | { |
||
36 | $primary = $this->primary; |
||
37 | |||
38 | if (is_callable($primary)) { |
||
39 | return $primary($this->getModel()); |
||
40 | } |
||
41 | |||
42 | return $primary ?: optional($this->getModel())->getKey(); |
||
43 | } |
||
44 | |||
45 | public function setPrimary($primary) |
||
46 | { |
||
47 | $this->primary = $primary; |
||
48 | |||
49 | return $this; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @param string $label |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | public function setLabel($label) |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | public function getLabel() |
||
70 | } |
||
71 | } |
||
72 |