| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 | 
							- <?php
 - 
 - namespace App\Filament\Pages;
 - 
 - use App\Models\EsgMain;
 - use Filament\Forms\Components\Actions\Action;
 - use Filament\Forms\Components\FileUpload;
 - use Filament\Forms\Components\Tabs;
 - use Filament\Forms\Components\Tabs\Tab;
 - use Filament\Forms\Components\Textarea;
 - use Filament\Forms\Components\TextInput;
 - use Filament\Forms\Concerns\InteractsWithForms;
 - use Filament\Forms\Form;
 - use Filament\Notifications\Notification;
 - use Filament\Pages\Page;
 - use SolutionForest\FilamentTranslateField\Forms\Component\Translate;
 - 
 - class EsgMainPage extends Page
 - {
 -     use InteractsWithForms;
 - 
 -     protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
 -     protected static ?string $navigationLabel = 'ESG 主要設定';
 -     protected static ?string $title = 'ESG 主要設定';
 -     protected static string $view = 'filament.pages.esg-main';
 -     protected static ?string $navigationGroup = 'ESG 上稿內容管理';
 -     protected static ?int $navigationSort = 99;
 - 
 -     public ?array $data = [];
 -     protected ?EsgMain $esgMain = null;
 - 
 -     public function mount(): void
 -     {
 -         $this->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::getMain();
 -             $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'),
 -         ];
 -     }
 - 
 - }
 
 
  |