Completed
Push — master ( 062b68...81f5ad )
by Terzi
08:48
created

HasOne::only()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Terranet\Administrator\Field;
4
5
use App\User;
6
use Illuminate\Support\Facades\View;
7
use Terranet\Administrator\Scaffolding;
8
use Terranet\Administrator\Traits\Module\HasColumns;
9
10
class HasOne extends BelongsTo
11
{
12
    use HasColumns;
0 ignored issues
show
Bug introduced by
The trait Terranet\Administrator\Traits\Module\HasColumns requires the property $includeDateColumns which is not provided by Terranet\Administrator\Field\HasOne.
Loading history...
13
14
    /** @var null|array */
15
    protected $only;
16
17
    /** @var null|array */
18
    protected $except;
19
20
    /**
21
     * @return array
22
     */
23
    protected function onEdit(): array
24
    {
25
        $relation = $this->model->{$this->id()}();
26
27
        $related = $relation->getRelated();
28
        $columns = $this->collectColumns($related)
29
                        ->without(array_merge([$related->getKeyName()], $this->except ?? []))
30
                        ->only($this->only)
31
                        ->each(function ($field) {
32
                            $field->setId(
33
                                "{$this->id()}.{$field->id()}"
34
                            );
35
                        });
36
37
        return [
38
            'columns' => $columns,
39
        ];
40
    }
41
42
    /**
43
     * @param array $only
44
     * @return self
45
     */
46
    public function only(array $only): self
47
    {
48
        $this->only = $only;
49
50
        return $this;
51
    }
52
53
    /**
54
     * @param array $except
55
     * @return self
56
     */
57
    public function except(array $except): self
58
    {
59
        $this->except = $except;
60
61
        return $this;
62
    }
63
}