esgMain = EsgMain::getMain(); $esgMainArray = $this->esgMain->safeToArray(); \Log::info("輸出", $esgMainArray); $this->form->fill($esgMainArray); } public function form(Form $form): Form { return $form ->schema([ Tabs::make('設定')->tabs([ Tab::make('基本資訊')->schema([ Translate::make()->schema(fn (string $locale) => [ TextInput::make('title') ->label("標題"), Textarea::make('description') ])->locales(["zh_TW", "en"]) ->columnSpanFull(), FileUpload::make('banner_pc')->label("Banner (PC)") ->disk("public") ->directory("esg"), FileUpload::make('banner_mobile')->label("Banner (Mobile)") ->disk("public") ->directory("esg"), ]), Tab::make('SEO 設定')->schema([ Translate::make()->schema(fn (string $locale) => [ TextInput::make('meta_title'), TextInput::make('meta_keyword'), Textarea::make('meta_description'), ])->locales(["zh_TW", "en"]) ->columnSpanFull(), FileUpload::make('og_img') ->disk("public") ->directory("esg"), ]), ]) ]) ->statePath('data'); } public function save(): void { try { $data = $this->form->getState(); $settings = EsgMain::getSettings(); $settings->update($data); Notification::make() ->title('設定已儲存') ->success() ->send(); } catch (\Exception $e) { Notification::make() ->title('儲存失敗') ->body($e->getMessage()) ->danger() ->send(); } } protected function getFormActions(): array { return [ Action::make('save') ->label('儲存設定') ->action('save') ->color('primary'), ]; } }