Server : Apache System : Linux 145.162.205.92.host.secureserver.net 5.14.0-611.45.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 1 05:56:53 EDT 2026 x86_64 User : tradze ( 1001) PHP Version : 8.1.34 Disable Function : NONE Directory : /home/tradze/www/app/Modules/Users/Repositories/ |
<?php
namespace App\Modules\Users\Repositories;
// use Cmgmyr\Messenger\Models\Thread;
use App\Modules\Users\Models\Thread;
use Illuminate\Support\Facades\Mail;
use App\Modules\Notifications\Facades\NotifRepository;
class MessageThreadRepository
{
/**
* @var Thread
*/
protected $thread;
/**
* MessageRepository constructor.
*/
public function __construct(Thread $thread)
{
$this->thread = $thread;
if ($this->thread)
return null;
}
/**
* Mail participants excepts the one who wrote the last message
*/
public function new_message_participants($exclude_user_id = false)
{
$user = $this->thread->participants()->where('user_id', '=', $exclude_user_id)->get();
foreach ($user as $participant)
$username = $participant->user->name;
//select all participanet except the one who send the message
if ($exclude_user_id) {
$participants = $this->thread->participants()->where('user_id', '!=', $exclude_user_id)->get();
} else {
//all participants
$participants = $this->thread->participants()->get();
}
//if no participants, stop script
if (!$participants)
return null;
$data = [];
$data['to'] = [];
foreach ($participants as $participant) {
if (isset($participant->user) && isset($participant->user->email))
$data['to'][] = $participant->user->email;
}
// dd($data['to']);
if (count($data['to']) > 0) {
$view = view('users::frontend.emails.booking_thread_message', ['thread' => $this->thread]);
//send confirmation email
Mail::send('users::frontend.emails.booking_thread_message', ['thread' => $this->thread], function ($m) use ($data) {
$m->from(env('MAIL_FROM'), env('APP_NAME'));
$m->to($data['to']);
$m->cc(env('MAIL_ADMIN_ADDR'));
$m->subject('Tradze Massage website – new message');
});
}
//mobile push notification
//get thread last message
$message = $this->thread->messages()->orderBy('created_at', 'desc')->first();
//send the message to the participants
foreach ($participants as $participant) {
if (isset($participant->user)) {
NotifRepository::add($participant->user->id, $message->body, 'message', $username);
}
} //endforeach
}
}