| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
-
- namespace App\Filament\Resources;
-
- use AbdulmajeedJamaan\FilamentTranslatableTabs\TranslatableTabs;
- use App\Filament\Resources\ProjectResource\Pages;
- use App\Filament\Resources\ProjectResource\RelationManagers;
- use App\Models\Project;
- use App\Models\Region;
- use Filament\Forms;
- use Filament\Forms\Components\DatePicker;
- use Filament\Forms\Components\FileUpload;
- use Filament\Forms\Components\Group;
- use Filament\Forms\Components\Repeater;
- use Filament\Forms\Components\Section;
- use Filament\Forms\Components\Select;
- use Filament\Forms\Components\Tabs;
- use Filament\Forms\Components\Tabs\Tab;
- use Filament\Forms\Components\Textarea;
- use Filament\Forms\Components\TextInput;
- use Filament\Forms\Form;
- use Filament\Forms\Get;
- use Filament\Resources\Resource;
- use Filament\Tables;
- use Filament\Tables\Table;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\SoftDeletingScope;
- use Illuminate\Support\Facades\Storage;
-
- class ProjectResource extends Resource
- {
- protected static ?string $model = Project::class;
-
- protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
- protected static ?string $navigationLabel = "專案項目管理";
- protected static ?string $modelLabel = "專案項目管理";
-
- public static function form(Form $form): Form
- {
- return $form
- ->schema([
- Section::make("")->schema([
- Select::make("region_id")->label("地區")->options(function (){
- return Region::where("visible",true)->pluck("name", "id");
- }),
- Select::make('tags')
- ->multiple()
- ->relationship('tags', 'name')
- ->preload()
- ->label('標籤'),
- TextInput::make("name")->label("項目名稱")->translatableTabs(),
- FileUpload::make("img_url")->label("圖片")->directory("project"),
- TextInput::make("img_alt")->label("圖片註釋")->translatableTabs(),
- Tabs::make()->tabs([
- Tab::make("專案概要")->schema([
- TranslatableTabs::make('')
- ->schema([
- TextInput::make("address")->label("地址"),
- Textarea::make("floor_plan")->label("樓層規劃"),
- Textarea::make("building_structure")->label("建築結構"),
- Textarea::make("design_unit")->label("設計團隊")
- ])
- ->columnSpanFull(),
- Select::make('badges')
- ->multiple()
- ->relationship('badges', 'title')
- ->getOptionLabelFromRecordUsing(function ($record) {
- $imageHtml = $record->img_url
- ? '<img src="' . Storage::url($record->img_url) . '" class="w-6 h-6 rounded-full mr-2 inline-block" />'
- : '<div class="w-6 h-6 bg-gray-200 rounded-full mr-2 inline-block"></div>';
-
- return new \Illuminate\Support\HtmlString($imageHtml . $record->title);
- })
- ->allowHtml()
- ->preload()
- ->label('取得標章')
- ->maxItems(8)
- ->required(),
- Repeater::make("summaries")->label("")->schema([
- TranslatableTabs::make('')
- ->schema([
- TextInput::make("title")->label("標題")->columnSpanFull(),
- Textarea::make("content")->label("內文")->columnSpanFull()
- ])->columnSpanFull(),
- ])
- ->relationship("summaries")
- ->label("")
- ->collapsible()
- ->reorderableWithButtons()
- ->orderColumn('order')
- ->cloneable(),
- ]),
- Tab::make("開發歷程")->schema([
- Repeater::make("histories")->label("")->schema([
- DatePicker::make("operate_date")->label("歷程日期")->columnSpan(1),
- TextInput::make("title")->label("標題")->translatableTabs()->columnSpanFull()
- ])
- ->relationship("histories", function ($query,Get $get, $livewire) {
- return $query->orderby("operate_date","desc");
- })
- ->collapsible()
- ->cloneable()
- ]),
- Tab::make("空間資訊")->schema([
- Repeater::make("spaceInfos")->label("")->schema([
- TranslatableTabs::make('')
- ->schema([
- TextInput::make("title")->label("標題")->columnSpanFull(),
- Textarea::make("content")->label("內文")->columnSpanFull()
- ])->columnSpanFull(),
- ])
- ->relationship("spaceInfos")
- ->label("")
- ->collapsible()
- ->reorderableWithButtons()
- ->orderColumn('order')
- ->cloneable(),
- ])
- ])
- ]),
- ]);
- }
-
- public static function table(Table $table): Table
- {
- return $table
- ->columns([
- //
- ])
- ->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'),
- ];
- }
- }
|