1 month ago

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


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);   
            DB::table('dispatch_subjob')->where('id', $id)->delete();

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