relations table get data

i have 2 selections supplier and brand. in supplier table i have brand_id column i want when i choose supplier brand selection should shows me only brands which is in supplier brand_id have. i trying to do it using option and filter it but its not works, there is my code


   Select::make('supplier_id')
                    ->label('Supplier')
                    ->relationship('supplier', 'name')
                    ->searchable()
                    ->required()
                    ->preload()
                    
                    ]),
                Select::make('brand_id')
                    ->label('Brand')
                    ->relationship('brand', 'name')
                    ->searchable()
                    ->required()
                    ->preload()
                    ->options(function () {
                        $supplierBrandIds = Supplier::pluck('brand_id')->toArray();
                        return Brand::whereIn('id', $supplierBrandIds)->get()->pluck('name', 'id');
                    })

                    ->createOptionForm([
                        TextInput::make('name')
                            ->required()
                            ->label('New Brand'),
                    ]),
Was this page helpful?