new ataxchments preview code
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Modules\Helpdesk\Models\Attachment;
|
||||
use Modules\Helpdesk\Services\AttachmentService;
|
||||
|
||||
final class AttachmentDeleteController extends Controller
|
||||
{
|
||||
/**
|
||||
* Soft-delete a Helpdesk attachment after enforcing ticket update access.
|
||||
*/
|
||||
public function __invoke(Attachment $attachment, AttachmentService $attachments): RedirectResponse
|
||||
{
|
||||
$ticket = $attachment->ticket;
|
||||
abort_if($ticket === null, 404);
|
||||
|
||||
Gate::authorize('update', $ticket);
|
||||
|
||||
if (Schema::hasColumn('helpdesk_attachments', 'deleted_at')) {
|
||||
$attachments->softDelete($attachment, (int) auth()->id());
|
||||
} else {
|
||||
$attachments->delete($attachment);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('helpdesk.tickets.show', $ticket)
|
||||
->with('ticket-attachments-deleted', 'Attachment removed.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user