dev-think-one /
nova-thinkit
| 1 | <?php |
||
| 2 | |||
| 3 | namespace NovaThinKit\Nova\ResourceTemplates; |
||
| 4 | |||
| 5 | use Laravel\Nova\Fields\Select; |
||
| 6 | use Laravel\Nova\Http\Requests\NovaRequest; |
||
| 7 | |||
| 8 | trait HasTemplate |
||
| 9 | { |
||
| 10 | 7 | public function templateKeyName(): string |
|
| 11 | { |
||
| 12 | 7 | return 'template'; |
|
| 13 | } |
||
| 14 | 7 | protected function templateFields(NovaRequest $request): array |
|
| 15 | { |
||
| 16 | 7 | return [ |
|
| 17 | 7 | Select::make('Template', $this->templateKeyName()) |
|
| 18 | 7 | ->placeholder('Default') |
|
| 19 | 7 | ->searchable() |
|
| 20 | 7 | ->options(TemplateFinder::templatesNames(static::$model)) |
|
| 21 | 7 | ->displayUsingLabels() |
|
| 22 | 7 | ->nullable(), |
|
| 23 | 7 | ...$this->selectedTemplateFields($request), |
|
| 24 | 7 | ]; |
|
| 25 | } |
||
| 26 | |||
| 27 | 7 | protected function selectedTemplateFields(NovaRequest $request): array |
|
| 28 | { |
||
| 29 | 7 | if ($this->resource->{$this->templateKeyName()}) { |
|
| 30 | 2 | return TemplateFinder::find($this->resource->{$this->templateKeyName()}, $this)?->fields($request) ?: []; |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 31 | } |
||
| 32 | |||
| 33 | 5 | return []; |
|
| 34 | } |
||
| 35 | } |
||
| 36 |