F
Filament14mo ago
Amitoj

How to get search record after choosing SELECT option?

Hi there, I am using the following code to obtain user_id (which belongs to user model). I am trying to forward the search record of selected user to another fields (i.e. phone_number) without using manual search query. Is there anyway that filaments provide to do the work, I failed to find related content on the documentation, thank you.
Select::make('user_id')
->label('Customer Email')
->relationship(name: 'user', titleAttribute: 'email')
->searchable()
->preload()
->required()

->afterStateUpdated(function (Set $set) {
$set('phone_number', 'Get customer phone number here');
}),
TextInput::make('phone_number')
->maxLength(50)
->required()
Select::make('user_id')
->label('Customer Email')
->relationship(name: 'user', titleAttribute: 'email')
->searchable()
->preload()
->required()

->afterStateUpdated(function (Set $set) {
$set('phone_number', 'Get customer phone number here');
}),
TextInput::make('phone_number')
->maxLength(50)
->required()
Solution:
Alright I figured it out, I used Select $component to get the values: ```php Select::make('user_id') ->label('Customer Email')...
Jump to solution
1 Reply
Solution
Amitoj
Amitoj14mo ago
Alright I figured it out, I used Select $component to get the values:
Select::make('user_id')
->label('Customer Email')
->relationship(name: 'user', titleAttribute: 'email')
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(function (Select $component, Set $set) {
$model = $component->getSelectedRecord();
$set('recipient_name', $model->name);
$set('phone_number', $model->phone_number);
}),
TextInput::make('recipient_name')
->maxLength(50)
->required(),
TextInput::make('phone_number')
->numeric()
->required()
Select::make('user_id')
->label('Customer Email')
->relationship(name: 'user', titleAttribute: 'email')
->searchable()
->preload()
->required()
->live()
->afterStateUpdated(function (Select $component, Set $set) {
$model = $component->getSelectedRecord();
$set('recipient_name', $model->name);
$set('phone_number', $model->phone_number);
}),
TextInput::make('recipient_name')
->maxLength(50)
->required(),
TextInput::make('phone_number')
->numeric()
->required()
Want results from more Discord servers?
Add your server