user destroying flow updated

This commit is contained in:
Sevan Nerse 2022-06-29 10:48:57 +03:00
parent 127d85d0d9
commit c846aa0005
5 changed files with 8 additions and 34 deletions

View File

@ -16,6 +16,8 @@ class DeleteUser extends Job implements ShouldDelete
event(new UserDeleting($this->model));
\DB::transaction(function () {
$this->deleteRelationships($this->model, ['invitation']);
$this->model->delete();
$this->model->flushCache();

View File

@ -1,28 +0,0 @@
<?php
namespace App\Listeners\Auth;
use App\Events\Auth\UserDeleted as Event;
use App\Jobs\Auth\DeleteInvitation;
use App\Models\Auth\UserInvitation;
use App\Traits\Jobs;
class DeleteUserInvitation
{
use Jobs;
/**
* Handle the event.
*
* @param $event
* @return void
*/
public function handle(Event $event)
{
$invitations = UserInvitation::where('user_id', $event->user->id)->get();
foreach ($invitations as $invitation) {
$this->dispatch(new DeleteInvitation($invitation));
}
}
}

View File

@ -58,6 +58,7 @@ class Version304 extends Listener
$files = [
'app/Events/Auth/InvitationCreated.php',
'app/Listeners/Auth/SendUserInvitation.php',
'app/Listeners/Auth/DeleteUserInvitation.php',
];
foreach ($files as $file) {

View File

@ -89,6 +89,11 @@ class User extends Authenticatable implements HasLocalePreference
return $this->belongsToMany('App\Models\Common\Dashboard', 'App\Models\Auth\UserDashboard');
}
public function invitation()
{
return $this->hasOne('App\Models\Auth\UserInvitation', 'user_id', 'id');
}
/**
* Always capitalize the name when we retrieve it
*/

View File

@ -32,12 +32,6 @@ class Event extends Provider
'App\Events\Auth\LandingPageShowing' => [
'App\Listeners\Auth\AddLandingPages',
],
'App\Events\Auth\InvitationCreated' => [
'App\Listeners\Auth\SendUserInvitation',
],
'App\Events\Auth\UserDeleted' => [
'App\Listeners\Auth\DeleteUserInvitation',
],
'App\Events\Document\DocumentCreated' => [
'App\Listeners\Document\CreateDocumentCreatedHistory',
'App\Listeners\Document\IncreaseNextDocumentNumber',