| Total Complexity | 5 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | trait HasFragments |
||
| 8 | { |
||
| 9 | public function getFragments(string $key): Collection |
||
| 10 | { |
||
| 11 | return $this->fragments()->where('key', $key)->orderBy('order', 'ASC')->get(); |
||
| 12 | } |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Save a single fragment and return the record id |
||
| 16 | * |
||
| 17 | * @param Fragment $fragment |
||
| 18 | * @return int |
||
| 19 | */ |
||
| 20 | public function saveFragment(Fragment $fragment, int $order): int |
||
| 21 | { |
||
| 22 | $values = array_merge([ |
||
| 23 | 'key' => $fragment->getKey(), 'order' => $order, |
||
| 24 | ], $fragment->getValues()); |
||
| 25 | |||
| 26 | if ($fragment->hasModelId()) { |
||
| 27 | $model =FragmentModel::find($fragment->getModelId()); |
||
| 28 | $model->update($values); |
||
| 29 | |||
| 30 | return $model->id; |
||
| 31 | } |
||
| 32 | |||
| 33 | return $this->fragments()->create($values)->id; |
||
| 34 | } |
||
| 35 | |||
| 36 | public function removeAllFragments(string $key, array $excludedFragmentIds): void |
||
| 39 | } |
||
| 40 | |||
| 41 | public function fragments() |
||
| 46 |