trs_matrimony/app/Services/ChatService.php
2024-08-22 09:31:12 +05:30

29 lines
729 B
PHP

<?php
namespace App\Services;
use App\Models\Chat;
class ChatService
{
public function store(array $data, $attachments)
{
$collection = collect($data);
$attachment = null;
$chat_thread_id = $data['chat_thread_id'];
$sender_user_id = auth()->user()->id;
$message = $data['message'];
if ($attachments != null) {
$attachment = implode(',', $attachments);
}
$data = $collection->merge(compact(
'chat_thread_id',
'sender_user_id',
'message',
'attachment'
))->toArray();
return Chat::create($data);
}
}