Файловый менеджер - Редактировать - /home/clickysoft/public_html/securebeans.clickysoft.net/app/Helpers/Helpers.php
Назад
<?php namespace App\Helpers; use App\Models\Token; use Mail; use LaravelFCM\Message\OptionsBuilder; use LaravelFCM\Message\PayloadNotificationBuilder; use LaravelFCM\Message\PayloadDataBuilder; use FCM; class Helpers { public static function getuserrole($id = 0, $type = '') { $roles = [ config('constants.ADMIN') => __('global.admin'), config('constants.SALOON') => __('global.saloon'), config('constants.TECHNISION') => __('global.technision'), config('constants.USER') => __('global.user'), ]; $roleName = ''; if ($id == 0) { if (!auth()->user()) { $roleName = ''; } else { // dd(auth()->user()->email); $roleName = auth()->user()->roles->pluck('name')[0]; } } else { $user = \App\Models\User::where(['id' => $id])->first(); // dd($user->email); $roleName = $user->roles->pluck('name')[0]; } if ($type == 'heading') { return $roles[$roleName]; } else { return $roleName; } } public static function SendEmail($to, $to_name, $subject, $body, $from = '', $from_name = '', $cc = null, $bcc = null) { if ($from == '') { $from = env('MAIL_SENDER_EMAIL'); } if ($from_name == '') { $from_name = env('MAIL_SENDER_NAME'); } $email = new \SendGrid\Mail\Mail(); $email->setFrom($from, $from_name); $email->setSubject($subject); if (is_array($to)) { for ($i = 0; $i < count($to); $i++) { $email->addTo($to[$i], (is_array($to_name) ? $to_name[$i] : $to_name)); } } else { $email->addTo($to, $to_name); } if ($cc !== null) { if (is_array($cc)) { for ($i = 0; $i < count($cc); $i++) { $email->addCC($cc[$i]); } } else { $email->addCC($cc); } } if ($bcc !== null) { if (is_array($bcc)) { for ($i = 0; $i < count($bcc); $i++) { $email->addBcc($bcc[$i]); } } else { $email->addBcc($bcc); } } // $email->addContent("text/plain", strip_tags($body)); $email->addContent("html", $body); $sendgrid = new \SendGrid(env('SENDGRID_API_KEY')); try { $response = $sendgrid->send($email); } catch (Exception $e) { $response = $e->getMessage(); } return $response; } public static function getFormattedReviewCount($count) { $thousand_reviews = $count / 1000; $million_reviews = $count / 1000000; //dd(0.002 > 0); //dd($million_reviews); if ($million_reviews > 1) { return $million_reviews . 'K'; } else if ($thousand_reviews > 1) { return $thousand_reviews . 'K'; } else { return $count; } } public static function email($request){ // if(isset($request->salon_id)){ $saloondata=Saloon::find($request->salon_id); $to="ar8497376@gmail.com"; Mail::send( 'email.mail',['saloondata'=>$saloondata],function($message) use ($to,$saloondata) { $message->to($to) ->subject('Laravel Test Mail'); $message->from('ghazanfar.art@gmail.com','Test Mail'); }); if (Mail::failures()) { dd("email not sent"); } if (isset($request->booker)) { $customer = auth()->user()->customer; $client_email = $customer->email; $client_name = $customer->first_name; $booking_id = Booking::latest()->first()->id; $booker_id = $request->booker_id; if ($request->booker == "technician") { $Technician = Technision::find($request->booker_id); $booker_name = $Technician->first_name; $booker_email = $Technician->email; $data = Booking::with(['services', 'technician' => function ($query) use ($booker_id) { $query->where('id', $booker_id); }])->find($booking_id); } else { $Saloon = Saloon::find($request->booker_id); $booker_name = $Saloon->name; $booker_email = $Saloon->email; $data = Booking::with(['services', 'saloon' => function ($query) use ($booker_id) { $query->where('id', $booker_id); }])->find($booking_id); } // $data = array('name'=>"Ogbonna Vitalis(sender_name)", 'body' => "A test mail from new project"); Mail::send('email.mail', ['data' => $data], function ($message) use ($client_name, $client_email, $data) { $message->to("ar8497376@gmail.com") ->subject('Laravel Test Mail'); $message->from('ghazanfar.art@gmail.com', 'Test Mail'); }); Mail::send('email.mail', ['data' => $data], function ($message) use ($booker_name, $booker_email, $data) { $message->to($booker_email) ->subject('Laravel Test Mail'); $message->from('ghazanfar.art@gmail.com', 'Test Mail'); }); if (Mail::failures()) { dd("email not sent"); } } } } public static function broadcastMessage($senderName, $message,$reciever_id) { $auth_id=auth()->user()->id; // dd($reciever_id); if (isset($request->booker)) { if ($request->booker == "technician") { $token_id = Technision::find($request->booker_id); } else { $token_id = Saloon::find($request->booker_id); } $optionBuilder = new OptionsBuilder(); $optionBuilder->setTimeToLive(60 * 20); $notificationBuilder = new PayloadNotificationBuilder('New message from : ' . $senderName); $notificationBuilder->setBody($message) ->setSound('default') ->setClickAction('http://127.0.0.1:8000/'); $dataBuilder = new PayloadDataBuilder(); $dataBuilder->addData([ 'sender_name' => $senderName, 'message' => $message, ]); $option = $optionBuilder->build(); $notification = $notificationBuilder->build(); $data = $dataBuilder->build(); $tokens = User::where('id', $token_id->user_id)->pluck('fcm_token')->toArray(); $downstreamResponse = FCM::sendTo($tokens, $option, $notification, $data); // dd($downstreamResponse); return $downstreamResponse->numberSuccess(); } else{ if(auth()->user()->hasRole('technician') ){ $path='http://127.0.0.1:8000/user/get-messages/'.$auth_id; } elseif(auth()->user()->hasRole('salon')){ $path='http://127.0.0.1:8000/user/get-messages/'.$auth_id; } else{ $technision= Technision::where('user_id',$reciever_id)->first(); if(!empty($technision)){ $path='http://127.0.0.1:8000/technician/messages/'.$auth_id; } else{ $path='http://127.0.0.1:8000/salon/messages/'.$auth_id; } } $message_sender_data=$senderName; $senderName=$senderName->first_name; $tokens = Token::where('user_id', $reciever_id)->pluck('tokens')->toArray(); // $tokens=User::all()->pluck('fcm_token')->toArray(); } $optionBuilder = new OptionsBuilder(); $optionBuilder->setTimeToLive(60 * 20); $notificationBuilder = new PayloadNotificationBuilder('New message from : ' . $senderName); $notificationBuilder->setBody($message) ->setSound('default') ->setClickAction($path); $dataBuilder = new PayloadDataBuilder(); $dataBuilder->addData([ 'sender_name' => $senderName, 'message' => $message, 'sender_picture'=> $message_sender_data->profile_picture, ]); $option = $optionBuilder->build(); $notification = $notificationBuilder->build(); $data = $dataBuilder->build(); // $tokens = User::where('id', $token_id->user_id)->pluck('fcm_token')->toArray(); $downstreamResponse = FCM::sendTo($tokens, $option, $notification, $data); // dd($downstreamResponse); return $downstreamResponse->numberSuccess(); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка