getRelationshipTypeByType('child')->id; $relationshipParentTypeId = $account->getRelationshipTypeByType('parent')->id; $offsprings = DB::table('offsprings')->where('account_id', $account->id)->get(); foreach ($offsprings as $offspring) { DB::table('relationships')->insert([ [ 'account_id' => $account->id, 'contact_is' => $offspring->is_the_child_of, 'relationship_type_name' => 'child', 'of_contact' => $offspring->contact_id, 'relationship_type_id' => $relationshipChildTypeId, ], [ 'account_id' => $account->id, 'contact_is' => $offspring->contact_id, 'relationship_type_name' => 'parent', 'of_contact' => $offspring->is_the_child_of, 'relationship_type_id' => $relationshipParentTypeId, ], ]); } } }); Schema::dropIfExists('offsprings'); Schema::dropIfExists('progenitors'); } }