dev-think-one /
nova-flexible-content
| 1 | <?php |
||
| 2 | |||
| 3 | namespace NovaFlexibleContent\Layouts\LayoutTraits; |
||
| 4 | |||
| 5 | use Laravel\Nova\Fields\FieldCollection; |
||
| 6 | use Laravel\Nova\Http\Requests\NovaRequest; |
||
| 7 | |||
| 8 | trait HasFieldsCollection |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * The layout's registered fields. |
||
| 12 | */ |
||
| 13 | protected ?FieldCollection $fields = null; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Provided by developer fields. |
||
| 17 | */ |
||
| 18 | 2 | protected function fields(): array |
|
| 19 | { |
||
| 20 | 2 | return $this->fields ? $this->fields->all() : []; |
|
| 21 | } |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Retrieve the layout's fields as a collection. |
||
| 25 | */ |
||
| 26 | 17 | public function fieldsCollection(): FieldCollection |
|
| 27 | { |
||
| 28 | 17 | $fields = $this->fields; |
|
| 29 | 17 | if(!$fields || $fields->isEmpty()) { |
|
| 30 | 17 | $fields = $this->fields(); |
|
| 31 | } |
||
| 32 | |||
| 33 | 17 | return FieldCollection::make($fields); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Filter the layout's fields for detail view. |
||
| 38 | */ |
||
| 39 | 1 | public function filterForDetail(NovaRequest $request, mixed $resource): static |
|
| 40 | { |
||
| 41 | 1 | $this->fields = $this->fieldsCollection()->filterForDetail($request, $resource); |
|
| 42 | |||
| 43 | 1 | return $this; |
|
| 44 | } |
||
| 45 | } |
||
| 46 |