Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1225 #1226

Merged
merged 10 commits into from
Jun 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ public function update(AttributeForm $request, $id)
*/
public function destroy($id)
{
$this->organizationRepository->findOrFail($id);

try {
Event::dispatch('contact.organization.delete.before', $id);

Expand Down
10 changes: 10 additions & 0 deletions packages/Webkul/Contact/src/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,14 @@ class Organization extends Model implements OrganizationContract
'name',
'address',
];

/**
* Get persons
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function persons()
{
return $this->hasMany(PersonProxy::modelClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,19 @@ public function update(array $data, $id, $attribute = "id")

return $organization;
}

/**
* delete organization and it's persons
*
* @param int $id
* @return @void
*/
public function delete($id)
{
$organization = $this->model->findOrFail($id);

$organization->persons->each->delete();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause DDOS. Use single query to delete all the persons.

$organization->persons()->delete();


$organization->delete($id);
}
}
Loading