zaster
1 month ago
102
3
General

Deleting a record from a Many to Many Relationship

Posted 1 month ago by zaster

Dispatch and SubJob has a M to M relationship and i have made DispatchItem to access the pivot table

When i tried

$dispatch_item->delete();

it deleted the record from the pivot table

it also deletes the record from the sub_jobs table (Which i should NOT do)

I was able to do the below and achieve deleting a pivot record only. But how could i do it using eloquent

public function destroy($id)
{
$dispatch_item = DispatchItem::find($id);   
//$dispatch_item->delete();
            DB::table('dispatch_subjob')->where('id', $id)->delete();
}

Please sign in or create an account to participate in this conversation.