Файловый менеджер - Редактировать - /home/clickysoft/public_html/somni.clickysoft.net/app/Repositories/NotificationRepository.php
Назад
<?php namespace App\Repositories; use App\Interfaces\NotificationRepositoryInterface; use App\Models\Property; use App\Models\Unit; use App\Models\Country; use App\Models\City; use App\Models\State; use App\Models\User; use App\Models\UserInfo; use App\Models\Newsletter; use App\Models\Notification; use App\Models\InvitationPropertyUnit; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Str; class NotificationRepository implements NotificationRepositoryInterface { public function CreateAndSendNotification($user, $title, $message){ $noti['user_id'] = $user->id; $noti['title'] = $title; $noti['message'] = $message; $noti['created_at'] = now(); $noti['status'] = 0; //Unread Notification::create($noti); $userObj = User::whereId($user->id)->first(); if(isset($userObj) && $userObj->isDesktopNotificationEnabled()){ $url = 'https://fcm.googleapis.com/fcm/send'; $FcmToken = User::where('id',$user->id)->pluck('device_token')->first(); // $FcmToken = User::whereNotNull('device_token')->pluck('device_token')->all(); $serverKey = config('constants.firebase.server_key'); // ADD SERVER KEY HERE PROVIDED BY FCM $data = [ "registration_ids" => [$FcmToken], "notification" => [ "title" => $title, "body" => $message, ] ]; $encodedData = json_encode($data); $headers = [ 'Authorization:key=' . $serverKey, 'Content-Type: application/json', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); // Disabling SSL Certificate support temporarly curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, $encodedData); // Execute post $result = curl_exec($ch); if ($result === FALSE) { \Log::info('This is notification log, Curl failed: ', [curl_error($ch)]); // die('Curl failed: ' . curl_error($ch)); } // Close connection curl_close($ch); // FCM response \Log::info('This is notification log: ', [$result]); return $result; } // dd($result); } public function unreadCount($user_id){ return $count = Notification::where('user_id',$user_id)->where('status',0)->orderBy('created_at','DESC')->count(); } public function recentNotifications($user_id){ return $notis = Notification::where('user_id',$user_id)->where('status',0)->orderBy('created_at','DESC')->limit(config('constants.notification.limit'))->get(); } public function recentNotificationsAll($user_id){ return $notis = Notification::where('user_id',$user_id)->orderBy('created_at','DESC')->get(); } public function markAllNotificationsRead($user_id){ return $read = Notification::where('user_id',$user_id)->update(['status' => 1]); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка