Issue with Dependent Select for MorphToSelect

In my CouponResource.php page, I am trying to have dependent select for 'assigned_to' field. I am experiencing very slow load while assigning 'assigned_to' field.
Group::make()
->relationship('advertisement')
->schema([
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(Company::class)
->titleAttribute('name'),
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
])
->searchable()
->live()
->afterStateUpdated(function (Set $set) {
$set('assigned_to', null);
})
->required(),
]),
Forms\Components\Select::make('assigned_to')
->relationship(
name: 'assignedTo',
titleAttribute: 'name',
modifyQueryUsing: function (Builder $query, Get $get) {
$selectedMember = $get('member');
if ($selectedMember) {
if ($selectedMember['memberable_type'] === Company::class) {
$company = Company::with('users')->find($selectedMember['memberable_id']);
if ($company) {
$query->whereIn('id', $company->users->pluck('id'));
}
}
}
return $query;
}
)
->preload()
->required(),
])
->columns(2)
->columnSpanFull(),

Group::make()
->relationship('advertisement')
->schema([
Group::make()
->relationship('member')
->schema([
MorphToSelect::make('memberable')
->types([
MorphToSelect\Type::make(Company::class)
->titleAttribute('name'),
MorphToSelect\Type::make(User::class)
->titleAttribute('name'),
])
->searchable()
->live()
->afterStateUpdated(function (Set $set) {
$set('assigned_to', null);
})
->required(),
]),
Forms\Components\Select::make('assigned_to')
->relationship(
name: 'assignedTo',
titleAttribute: 'name',
modifyQueryUsing: function (Builder $query, Get $get) {
$selectedMember = $get('member');
if ($selectedMember) {
if ($selectedMember['memberable_type'] === Company::class) {
$company = Company::with('users')->find($selectedMember['memberable_id']);
if ($company) {
$query->whereIn('id', $company->users->pluck('id'));
}
}
}
return $query;
}
)
->preload()
->required(),
])
->columns(2)
->columnSpanFull(),

0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server