CheckboxList (bulkTogglable) issue

When using clicking on "select all" on the create page it will also select the hidden values based on the custom queries.
1 Reply
BlackShadow
BlackShadow12mo ago
Relationship Function:
// Search for the company
if ($livewire instanceof CompanyResource\RelationManagers\AgreementsRelationManager) {
$company = $livewire->getRelationship()->getParent();
} elseif ($get('company_id')) {
$company = Company::find($get('company_id'));
}

if (isset($company) && $get('method') && $get('type') && $get('category_id')) {

// Get the companies similar agreements
$agreements = $company->agreements()
->where('type', $get('type'))
->where('method', $get('method'))
->where('category_id', $get('category_id'))
->where(function ($query) use ($livewire) {
if (isset($livewire->record->id)) {
$query->where('id', '!=', $livewire->record->id);
}
})
->get();

// Get all the provinces selected from the similar agreements
$provincesAlreadyInUse = [];
foreach ($agreements as $agreement) {
foreach ($agreement->provinces as $province) {
$provincesAlreadyInUse[] = $province->id;
}
}

$query->whereNotIn('id', $provincesAlreadyInUse);

}

return $query;
// Search for the company
if ($livewire instanceof CompanyResource\RelationManagers\AgreementsRelationManager) {
$company = $livewire->getRelationship()->getParent();
} elseif ($get('company_id')) {
$company = Company::find($get('company_id'));
}

if (isset($company) && $get('method') && $get('type') && $get('category_id')) {

// Get the companies similar agreements
$agreements = $company->agreements()
->where('type', $get('type'))
->where('method', $get('method'))
->where('category_id', $get('category_id'))
->where(function ($query) use ($livewire) {
if (isset($livewire->record->id)) {
$query->where('id', '!=', $livewire->record->id);
}
})
->get();

// Get all the provinces selected from the similar agreements
$provincesAlreadyInUse = [];
foreach ($agreements as $agreement) {
foreach ($agreement->provinces as $province) {
$provincesAlreadyInUse[] = $province->id;
}
}

$query->whereNotIn('id', $provincesAlreadyInUse);

}

return $query;