columns([ Tables\Columns\TextColumn::make('name')->label('Nome'), Tables\Columns\TextColumn::make('city.name')->label('Cidade') ->getStateUsing(function (Place $record) { return "{$record->city->name} - {$record->city->state->acronym}"; }), ]) ->filters([ Tables\Filters\Filter::make('name')->form([ TextInput::make('name')->label('Nome'), ])->query(function (Builder $query, array $data) { return $query->where('name', 'LIKE', '%' . $data['name'] . '%'); }), Tables\Filters\Filter::make('city')->form([ TextInput::make('city')->label('Cidade'), ])->query(function (Builder $query, array $data) { return $query->whereHas('city', function ($query) use ($data) { return $query->where('name', 'LIKE', '%' . $data['city'] . '%'); }); }), Tables\Filters\SelectFilter::make('categories') ->label('Categorias') ->multiple() ->relationship(name: 'categories', titleAttribute: 'name') ->preload(), Tables\Filters\Filter::make('is_approved')->label('Aprovado')->toggle(), Tables\Filters\TrashedFilter::make(), ]) ->actions([ Tables\Actions\EditAction::make(), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ Tables\Actions\DeleteBulkAction::make(), Tables\Actions\ForceDeleteBulkAction::make(), Tables\Actions\RestoreBulkAction::make(), ]), ]); } public static function form(Form $form): Form { return $form ->schema([ Forms\Components\Hidden::make('id'), Forms\Components\TextInput::make('name')->label('Nome')->required() ->columnSpan('full'), Forms\Components\RichEditor::make('description')->label('Descrição') ->columnSpan('full'), Forms\Components\TextInput::make('website')->label('Website'), Forms\Components\TextInput::make('phone')->label('Telefone') ->mask(RawJs::make(<<<'JS' $input.length >= 14 ? '(99) 99999-9999' : '(99) 9999-9999' JS )), Geocomplete::make('details->address') ->label('Endereço') ->isLocation() ->geocodeOnLoad() ->updateLatLng(), // Forms\Components\TextInput::make('address')->label('Endereço'), Forms\Components\Select::make('city_id') ->label('Cidade') ->relationship(name: 'city', titleAttribute: 'name') ->getOptionLabelFromRecordUsing(fn($record) => "{$record->name} - {$record->state->acronym}") ->searchable(['name', 'slug']) ->required(), Forms\Components\Select::make('parent_id') ->label('Pai') ->relationship('parent', 'name') ->searchable() ->columnSpan('full'), Forms\Components\Select::make('owner_id') ->label('Dono') ->relationship('owner', 'name') ->searchable() ->columnSpan('full'), FilamentJsonColumn::make('details') ->label('Detalhes') ->columnSpan('full'), Forms\Components\FileUpload::make('images') ->columnSpan('full') ->label('Imagens') ->visibility('private') ->directory('places-images') ->reorderable() ->multiple(), Map::make('location') ->label("Localização do lugar") ->columnSpan('full'), Forms\Components\Toggle::make('is_approved')->label('Aprovado') ->hidden(fn() => auth()->user()->type !== UserType::SuperUser->value), ]); } public static function getRelations(): array { return [ CategoryRelationManager::class ]; } public static function getPages(): array { return [ 'index' => Pages\ListPlaces::route('/'), 'create' => Pages\CreatePlace::route('/create'), 'edit' => Pages\EditPlace::route('/{record}/edit'), ]; } public static function getEloquentQuery(): Builder { $query = parent::getEloquentQuery() ->withoutGlobalScopes([ SoftDeletingScope::class, ]); if (!auth()->user()->isSuperUser()) { $query->where('owner_id', auth()->id()); } return $query; } }