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'));
}
})