Skip to content

Commit

Permalink
Merge pull request krayin#1226 from prabhat-webkul/fix-#1225
Browse files Browse the repository at this point in the history
  • Loading branch information
devansh-webkul committed Jun 19, 2024
2 parents 6d39eae + cbf1de1 commit 8f35494
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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 @@ -3,6 +3,7 @@
namespace Webkul\Contact\Repositories;

use Illuminate\Container\Container;
use Illuminate\Support\Facades\DB;
use Webkul\Core\Eloquent\Repository;
use Webkul\Attribute\Repositories\AttributeValueRepository;

Expand Down Expand Up @@ -69,4 +70,26 @@ 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->findOrFail($id);

DB::transaction(function() use($organization, $id) {
$organization->persons()->delete();

$this->attributeValueRepository->deleteWhere([
'entity_id' => $id,
'entity_type' => 'organizations',
]);

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

0 comments on commit 8f35494

Please sign in to comment.