⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.94
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
hospital.dev-unit.com
/
app
/
Repositories
/
View File Name :
SmsRepository.php
<?php namespace App\Repositories; use App\Models\Sms; use App\Models\Subscription; use App\Models\User; use Exception; use Filament\Notifications\Notification; use Illuminate\Support\Facades\Auth; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; use Twilio\Exceptions\ConfigurationException; use Twilio\Rest\Client; /** * Class SmsRepository */ class SmsRepository extends BaseRepository { /** * @var array */ protected $fieldSearchable = [ 'user', 'message', ]; /** * @return array|string[] */ public function getFieldsSearchable() { return $this->fieldSearchable; } public function model(): string { return Sms::class; } public function store($input, $action) { if (isset($input['prefix_code'])) { $regionCode = getCountryCode($input['prefix_code']) ?? null; } if ($input['number_directly'] == false) { $userMobile = User::whereIn('id', $input['send_to'])->pluck('phone', 'id'); foreach ($userMobile as $key => $phone) { $this->sendSMS($key, null, $phone, $input['message'], $action); } } else { $this->sendSMS(null, $regionCode, $input['phone'], $input['message'], $action); } } /** * @throws ConfigurationException */ public function sendSMS($sendTo, $regionCode, $phone, $message, $action) { try { $sid = config('twilio.sid'); $token = config('twilio.token'); $client = new Client($sid, $token); $sms = Sms::create([ 'send_to' => $sendTo, 'region_code' => $regionCode, 'phone_number' => $phone, 'message' => $message, 'send_by' => Auth::user()->id, ]); $smsLimit = Subscription::whereUserId(getLoggedInUserId())->whereStatus(1)->value('sms_limit'); Subscription::whereUserId(getLoggedInUserId())->whereStatus(1)->update([ 'sms_limit' => $smsLimit - 1, ]); $client->messages->create( substr($phone, 0, 1) == '+' ? $phone : '+'.$sms->region_code.$sms->phone_number, [ 'from' => config('twilio.from_number'), 'body' => $message, ] ); } catch (Exception $e) { // throw new UnprocessableEntityHttpException($e->getMessage()); Notification::make() ->title($e->getMessage()) ->danger() ->send(); $action->halt; } } }