Files
CRM/app/Services/Contact/Conversation/DestroyMessage.php
Kroonk a213a1dba0
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
refactor: replace custom CRM with Monica fork
2026-05-22 16:19:55 +02:00

54 lines
1.3 KiB
PHP

<?php
/**
* This is a single action class, totally inspired by
* https://medium.com/@remi_collin/keeping-your-laravel-applications-dry-with-single-action-classes-6a950ec54d1d.
*/
namespace App\Services\Contact\Conversation;
use App\Services\BaseService;
use App\Models\Contact\Message;
use App\Models\Contact\Conversation;
class DestroyMessage extends BaseService
{
/**
* Get the validation rules that apply to the service.
*
* @return array
*/
public function rules()
{
return [
'account_id' => 'required|integer|exists:accounts,id',
'conversation_id' => 'required|integer|exists:conversations,id',
'message_id' => 'required|integer|exists:messages,id',
];
}
/**
* Destroy a message.
*
* @param array $data
* @return bool
*/
public function execute(array $data): bool
{
$this->validate($data);
Conversation::where('account_id', $data['account_id'])
->findOrFail($data['conversation_id']);
$message = Message::where('account_id', $data['account_id'])
->where('conversation_id', $data['conversation_id'])
->findOrFail($data['message_id']);
$message->contact->throwInactive();
$message->delete();
return true;
}
}