Dynamic Select field default value HELP PLEASE <3
Hi,
I have the following code:
When you select the
Can you assist please?
I have the following code:
Select::make('organisation_id')
->relationship('organisations','label')
->live()
->required()
->afterStateUpdated(function($state,$set,$component,$livewire){
if($state) {
$default=Organisation::find($state)->defaultInvoiceRecipient;
if ($default) {
$set('invoice_recipient_id', $default->id);
}
}
}),
Select::make('invoice_recipient_id')
->visible(fn($get)=>$get('organisation_id'))
->required()
->relationship('invoiceRecipient', 'company_entity',function ($query,$get,$set){
if($get('organisation_id')){
$query->where('organisation_id',$get('organisation_id'));
}
})Select::make('organisation_id')
->relationship('organisations','label')
->live()
->required()
->afterStateUpdated(function($state,$set,$component,$livewire){
if($state) {
$default=Organisation::find($state)->defaultInvoiceRecipient;
if ($default) {
$set('invoice_recipient_id', $default->id);
}
}
}),
Select::make('invoice_recipient_id')
->visible(fn($get)=>$get('organisation_id'))
->required()
->relationship('invoiceRecipient', 'company_entity',function ($query,$get,$set){
if($get('organisation_id')){
$query->where('organisation_id',$get('organisation_id'));
}
})When you select the
organisation_idorganisation_id should automatically select the default value of the invoice_recipient_idinvoice_recipient_id but unfortunately doesn't.Can you assist please?