adrema/app/Member/Actions/MemberDeleteAction.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2023-08-15 23:03:51 +02:00
<?php
namespace App\Member\Actions;
use App\Lib\JobMiddleware\WithJobState;
2023-08-15 23:03:51 +02:00
use App\Maildispatcher\Actions\ResyncAction;
use App\Member\Member;
use Illuminate\Http\RedirectResponse;
use Lorisleiva\Actions\Concerns\AsAction;
class MemberDeleteAction
{
use AsAction;
public function handle(int $memberId): void
2023-08-15 23:03:51 +02:00
{
$member = Member::findOrFail($memberId);
2023-08-15 23:03:51 +02:00
if ($member->nami_id) {
NamiDeleteMemberAction::run($member->nami_id);
2023-08-15 23:03:51 +02:00
}
$member->delete();
ResyncAction::run();
}
public function asController(Member $member): RedirectResponse
{
static::dispatch($member->id);
2023-08-15 23:03:51 +02:00
return redirect()->back();
}
/**
* @return array<int, object>
*/
public function getJobMiddleware(int $memberId): array
{
$member = Member::findOrFail($memberId);
return [
WithJobState::make('member')
->before('Lösche Mitglied ' . $member->fullname)
->after('Mitglied ' . $member->fullname . ' gelöscht')
->shouldReload(),
];
}
2023-08-15 23:03:51 +02:00
}