RelationManager error when using custom create

I am getting a SQL general error stating that field 'is_approved' doesn't have a default value (which is correct, it doesn't). I am guessing I am missing something obvious in the code below when customizing my data prior to saving.
->headerActions([
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$role = Role::find($data['role_id']);

if ($role->entity_type == 'Program') {
$data['entity_id'] = $data['program_id'];
}

$data['entity_type'] = $role->entity_type;

$data['name'] = $role->name;

$data['is_approved'] = 0;

if(request()->user()->hasPermissionOnAny('StateAssociation', 'manage-users')){
$data['is_approved'] = 1;
}

return $data;
})

// Removed unrelated code here.

->using(function (RelationManager $livewire, array $data) {

return $livewire->getRelationship()->create($data);

})
->hidden(fn ( $livewire): string => $livewire instanceof ViewUser),

])
->headerActions([
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data): array {
$role = Role::find($data['role_id']);

if ($role->entity_type == 'Program') {
$data['entity_id'] = $data['program_id'];
}

$data['entity_type'] = $role->entity_type;

$data['name'] = $role->name;

$data['is_approved'] = 0;

if(request()->user()->hasPermissionOnAny('StateAssociation', 'manage-users')){
$data['is_approved'] = 1;
}

return $data;
})

// Removed unrelated code here.

->using(function (RelationManager $livewire, array $data) {

return $livewire->getRelationship()->create($data);

})
->hidden(fn ( $livewire): string => $livewire instanceof ViewUser),

])
1 Reply
nwalty
nwaltyOP2y ago
I should add, 'is_approved" is on a pivot table and is using withPivot()
Want results from more Discord servers?
Add your server