Skip to content

Commit 8f35494

Browse files
Merge pull request #1226 from prabhat-webkul/fix-#1225
Fixed #1225
2 parents 6d39eae + cbf1de1 commit 8f35494

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

packages/Webkul/Admin/src/Http/Controllers/Contact/OrganizationController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ public function update(AttributeForm $request, $id)
115115
*/
116116
public function destroy($id)
117117
{
118-
$this->organizationRepository->findOrFail($id);
119-
120118
try {
121119
Event::dispatch('contact.organization.delete.before', $id);
122120

packages/Webkul/Contact/src/Models/Organization.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,14 @@ class Organization extends Model implements OrganizationContract
2323
'name',
2424
'address',
2525
];
26+
27+
/**
28+
* Get persons.
29+
*
30+
* @return \Illuminate\Database\Eloquent\Relations\HasMany
31+
*/
32+
public function persons()
33+
{
34+
return $this->hasMany(PersonProxy::modelClass());
35+
}
2636
}

packages/Webkul/Contact/src/Repositories/OrganizationRepository.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Webkul\Contact\Repositories;
44

55
use Illuminate\Container\Container;
6+
use Illuminate\Support\Facades\DB;
67
use Webkul\Core\Eloquent\Repository;
78
use Webkul\Attribute\Repositories\AttributeValueRepository;
89

@@ -69,4 +70,26 @@ public function update(array $data, $id, $attribute = "id")
6970

7071
return $organization;
7172
}
73+
74+
/**
75+
* Delete organization and it's persons.
76+
*
77+
* @param int $id
78+
* @return @void
79+
*/
80+
public function delete($id)
81+
{
82+
$organization = $this->findOrFail($id);
83+
84+
DB::transaction(function() use($organization, $id) {
85+
$organization->persons()->delete();
86+
87+
$this->attributeValueRepository->deleteWhere([
88+
'entity_id' => $id,
89+
'entity_type' => 'organizations',
90+
]);
91+
92+
$organization->delete();
93+
});
94+
}
7295
}

0 commit comments

Comments
 (0)