schema([ TextInput::make('title')->required()->maxLength(255)->live(onBlur: true)->afterStateUpdated(fn ($state, $set) => $set('slug', \Illuminate\Support\Str::slug($state) . '-' . \Illuminate\Support\Str::random(4))), TextInput::make('slug')->required()->maxLength(255)->unique(ignoreRecord: true), Textarea::make('description')->rows(4), TextInput::make('price') ->numeric() ->currencyMask(thousandSeparator: ',', decimalSeparator: '.', precision: 2), Select::make('currency') ->options(fn () => ListingPanelHelper::currencyOptions()) ->default(fn () => ListingPanelHelper::defaultCurrency()) ->required(), Select::make('category_id')->label('Category')->options(fn () => Category::where('is_active', true)->pluck('name', 'id'))->searchable()->nullable(), StateFusionSelect::make('status')->required(), PhoneInput::make('contact_phone')->defaultCountry(CountryCodeManager::defaultCountryIso2())->nullable(), TextInput::make('contact_email')->email()->maxLength(255), TextInput::make('city')->maxLength(100), CountryCodeSelect::make('country') ->label('Country') ->default(fn () => CountryCodeManager::defaultCountryCode()) ->formatStateUsing(fn ($state): ?string => CountryCodeManager::countryCodeFromLabelOrCode($state)) ->dehydrateStateUsing(fn ($state, ?Listing $record): ?string => CountryCodeManager::normalizeStoredCountry($state ?? $record?->country)), Map::make('location') ->label('Location') ->visible(fn (): bool => ListingPanelHelper::googleMapsEnabled()) ->draggable() ->clickable() ->autocomplete('city') ->autocompleteReverse(true) ->reverseGeocode([ 'city' => '%L', ]) ->defaultLocation([41.0082, 28.9784]) ->defaultZoom(10) ->height('320px') ->columnSpanFull(), SpatieMediaLibraryFileUpload::make('images') ->collection('listing-images') ->multiple() ->image() ->reorderable(), ]); } public static function table(Table $table): Table { return $table->columns([ SpatieMediaLibraryImageColumn::make('images') ->collection('listing-images') ->circular(), TextColumn::make('title')->searchable()->sortable()->limit(40), TextColumn::make('category.name')->label('Category'), TextColumn::make('price') ->currency(fn (Listing $record): string => $record->currency ?: ListingPanelHelper::defaultCurrency()) ->sortable(), StateFusionSelectColumn::make('status'), TextColumn::make('city'), TextColumn::make('created_at')->dateTime()->sortable(), ])->filters([ StateFusionSelectFilter::make('status'), ])->actions([ EditAction::make(), Action::make('activities') ->icon('heroicon-o-clock') ->url(fn (Listing $record): string => static::getUrl('activities', ['record' => $record])), DeleteAction::make(), ]); } public static function getEloquentQuery(): Builder { return parent::getEloquentQuery()->where('user_id', Filament::auth()->id()); } public static function getPages(): array { return [ 'index' => Pages\ListListings::route('/'), 'create' => Pages\CreateListing::route('/create'), 'activities' => Pages\ListListingActivities::route('/{record}/activities'), 'edit' => Pages\EditListing::route('/{record}/edit'), ]; } }