| Total Complexity | 3 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class HasOne extends BelongsTo |
||
| 11 | { |
||
| 12 | use HasColumns; |
||
|
|
|||
| 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 |
||
| 62 | } |
||
| 63 | } |