schema([ Section::make("")->schema([ Translate::make()->schema(fn (string $locale) => [ TextInput::make("name")->label("項目名稱"), TextInput::make("sub_name")->label("項目子名稱"), ]) ->locales(["zh_TW", "en"]) ->actions([ app(DeepLService::class)->createTranslationAction("Main", ["name", "sub_name"]) ])->columnSpanFull()->id("main"), Select::make('tags') ->multiple() ->relationship('tags', 'name') ->preload() ->label('標籤'), FileUpload::make("img_url")->label("圖片")->directory("project")->multiple()->maxFiles(5), ]), Tabs::make()->schema([ Tab::make("專案概要")->schema([ Select::make("region_id")->label("地區")->options(function (){ return Region::where("visible",true)->pluck("name", "id"); }), Translate::make()->schema(fn (string $locale) => [ Textarea::make("summaries")->label("簡述"), TextInput::make("address")->label("地址"), Textarea::make("floor_plan")->label("樓層規劃"), Textarea::make("building_structure")->label("建築結構"), Textarea::make("design_unit")->label("設計團隊") ]) ->locales(["zh_TW", "en"]) ->actions([ app(DeepLService::class)->createTranslationAction("summaries", ["summaries","address", "floor_plan","building_structure","design_unit"]) ])->columnSpanFull()->id("summaries"), Select::make('badges') ->multiple() ->relationship('badges', 'title') ->getOptionLabelFromRecordUsing(function ($record) { $imageHtml = $record->img_url ? '' : '
'; return new \Illuminate\Support\HtmlString($imageHtml . $record->title); }) ->allowHtml() ->preload() ->label('取得標章') ->maxItems(8) ->required(), ]), Tab::make("開發歷程")->schema([ Repeater::make("histories")->label("")->schema([ TextInput::make('histories_item_key') ->default(fn () => Str::random()) ->hidden() ->afterStateHydrated(function (TextInput $component, $state) { if (empty($state)) { $component->state(Str::random()); } }), DatePicker::make("operate_date")->label("歷程日期")->columnSpan(1), Translate::make()->schema(fn (string $locale) => [ TextInput::make("title")->label("標題")->columnSpanFull() ]) ->locales(["zh_TW", "en"]) ->actions([ app(DeepLService::class)->createTranslationAction("histories", ["title"]) ])->columnSpanFull() ->id(fn ($get) => "histories_" . $get('histories_item_key')), ]) ->relationship("histories", function ($query,Get $get, $livewire) { return $query->orderby("operate_date","desc"); }) ->collapsible() ->cloneable() ]), Tab::make("空間資訊")->schema([ Group::make()->schema([ Translate::make()->schema(fn (string $locale) => [ TextInput::make("contact_unit")->label("物管單位"), TextInput::make("contact_phone")->label("物管電話"), TextInput::make("inversment_phone")->label("招商電話"), ]) ->locales(["zh_TW", "en"]) ->actions([ app(DeepLService::class)->createTranslationAction("contact", ["contact_unit", "contact_phone", "inversment_phone"]) ])->columnSpanFull()->columns(3) ->id("contact"), ])->columnSpanFull(), Repeater::make("spaceInfos")->label("")->schema([ Translate::make()->schema(fn (string $locale) => [ TextInput::make("title")->label("標題")->columnSpanFull(), Textarea::make("content")->label("內文")->columnSpanFull() ]) ->locales(["zh_TW", "en"]) ->actions([ app(DeepLService::class)->createTranslationAction("spaceInfos", ["title", "content"]) ])->columnSpanFull() ->id(fn ($get) => "spaceInfos_" . $get('item_key')), ]) ->relationship("spaceInfos") ->label("") ->collapsible() ->reorderableWithButtons() ->orderColumn('order') ->cloneable(), ]) ])->columnSpanFull(), ]); } public static function table(Table $table): Table { return $table ->columns([ // TextColumn::make("name")->label("項目名稱")->alignCenter(), ImageColumn::make("first_list_img_url")->label("列表圖")->alignCenter(), TextColumn::make("region.name")->label("地址")->alignCenter() ->formatStateUsing(fn ($record) => $record->region->getTranslation("name", "zh_TW") . ' | ' . $record->getTranslation("address", "zh_TW")), ]) ->filters([ // ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), ]), ]); } public static function getRelations(): array { return [ // ]; } public static function getPages(): array { return [ 'index' => Pages\ListProjects::route('/'), 'create' => Pages\CreateProject::route('/create'), 'edit' => Pages\EditProject::route('/{record}/edit'), ]; } }