Save relationship with pivot attributes/columns

I need some help.

How can i conditionally fill the pivot attribute/column when creating a Model from Select field using the createOptionForm.

here is what i am trying.

// Relationship defined in Model
public function tags(): MorphToMany
{
    return $this->morphToMany(Tag::class, 'taggable')
        ->wherePivot('is_approved', false);
}

// Select input in a resource form.
Select::make('tags')
    ->relationship('tags', 'name')
    ->multiple()
    ->createOptionForm([
        TextInput::make('name'),
    ])


When the relationship is saved, I need to set the is_approved column set to true/false based on a condition.

Thanks.
Was this page helpful?