yajra / laravel-address

Philippines Regions, Provinces, Cities and Barangays Address Lookup API for Laravel.
MIT License
35 stars 17 forks source link

Any Idea how to use this package in filament? #22

Open jeromevillaver opened 1 week ago

jeromevillaver commented 1 week ago

I want to apply this package in in the filament v3. based on the docs " On your view, include @include('address::form', ['model' => $modelWithAddress]) "

But what if in the filament v3?

This is just a sample only

Forms\Components\Fieldset::make('address')
                    ->schema([
                        Forms\Components\Select::make('region_id')
                            ->label('Region')
                            ->options(DB::table('regions')->pluck('name', 'id'))
                            ->reactive()
                            ->afterStateUpdated(fn (callable $set) => $set('province_id', null)),

                        Forms\Components\Select::make('province_id')
                            ->label('Province')
                            ->options(function (callable $get) {
                                $regionId = $get('region_id');
                                return $regionId
                                    ? DB::table('provinces')->where('region_id', $regionId)->pluck('name', 'id')
                                    : [];
                            })
                            ->reactive()
                            ->afterStateUpdated(fn (callable $set) => $set('city_id', null)),

                        Forms\Components\Select::make('city_id')
                            ->label('City')
                            ->options(function (callable $get) {
                                $provinceId = $get('province_id');
                                return $provinceId
                                    ? DB::table('cities')->where('province_id', $provinceId)->pluck('name', 'id')
                                    : [];
                            })
                            ->reactive()
                            ->afterStateUpdated(fn (callable $set) => $set('barangay_id', null)),

                        Forms\Components\Select::make('barangay_id')
                            ->label('Barangay')
                            ->options(function (callable $get) {
                                $cityId = $get('city_id');
                                return $cityId
                                    ? DB::table('barangays')->where('city_id', $cityId)->pluck('name', 'id')
                                    : [];
                            })
                            ->reactive(),

                        Forms\Components\TextInput::make('street')
                            ->label('Street'),
                ]),
   On that sample there is parent id for nested data.

   Hope you can update the docs on how to implement it in filament.
yajra commented 1 week ago

I am not using filament, I may not provide any docs.

But for the implementation, you must cascade the dropdowns starting from region -> province -> city -> barangay.

Select a Region -> filter provinces using selected region_id Select a Province -> filter cities using the selected province_id Select a City -> filter barangays using the selected city_id