detach item from pivot with repeater instead of deleting the other record

I have a issue when deleting the record from the pivot. It also deletes the customer instead of just removing the data from the pivot. It is a many to many relationship.
Section::make('Customer Information')
->schema([
Repeater::make('contacts')
->relationship('contacts')
->schema([
Forms\Components\Select::make('contact_id')
->label('Search Contact')
->searchable()
->getSearchResultsUsing(function (string $search) {
return Http::get(url('/contacts/search'), ['q' => $search])->json();
})
->getOptionLabelUsing(function ($value) {
$contact = Contact::find($value);
return $contact ? "{$contact->first_name} {$contact->last_name}" : null;
})
->reactive()
->afterStateUpdated(function ($set, $state) {
if ($state) {
$contact = Contact::find($state);
if ($contact) {
$set('first_name', $contact->first_name);
$set('last_name', $contact->last_name);
$set('email', $contact->email);
}
}
}),

TextInput::make('first_name')
->label('First Name')
->required(),
TextInput::make('last_name')
->label('Last Name')
->required(),
TextInput::make('email')
->label('Email')
->email()
->required()
->maxLength(255),
])
->columns(2),
])
]);
Section::make('Customer Information')
->schema([
Repeater::make('contacts')
->relationship('contacts')
->schema([
Forms\Components\Select::make('contact_id')
->label('Search Contact')
->searchable()
->getSearchResultsUsing(function (string $search) {
return Http::get(url('/contacts/search'), ['q' => $search])->json();
})
->getOptionLabelUsing(function ($value) {
$contact = Contact::find($value);
return $contact ? "{$contact->first_name} {$contact->last_name}" : null;
})
->reactive()
->afterStateUpdated(function ($set, $state) {
if ($state) {
$contact = Contact::find($state);
if ($contact) {
$set('first_name', $contact->first_name);
$set('last_name', $contact->last_name);
$set('email', $contact->email);
}
}
}),

TextInput::make('first_name')
->label('First Name')
->required(),
TextInput::make('last_name')
->label('Last Name')
->required(),
TextInput::make('email')
->label('Email')
->email()
->required()
->maxLength(255),
])
->columns(2),
])
]);
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?