diff --git a/readme.md b/readme.md index 03679e4..c32d98e 100644 --- a/readme.md +++ b/readme.md @@ -103,11 +103,15 @@ SMS::via(Ssl::class)->shootWithQueue("01XXXXXXXXX",'test sms'); # Log Generate -You can generate log in database for every sms api request and save in database. For doing this. Follow below points -1. Be confirm you have completed **step-2** and **step-3** -2. Run command ``php artisan migrate``. This will create ``lbs_log`` table in your database -3. Go to your project directory and locate ``config/sms.php`` -4. Find and make true ``'sms_log' => true,`` +You can generate log for every sms api request and save in database or file. For doing this. Follow below points +1. Laravelbdsms stores log in two drivers(`database, file`). `database` is default. You can change it from _config/sms.php_ +2. Find and make true `'sms_log' => true,` +3. Be confirm you have completed **step-2** and **step-3** +4. For `database` driver + 1. Change log driver to `log_driver =>'database'` from `config/sms.php` + 2. Run command `php artisan migrate`. This will create `lbs_log` table in your database +5. For `file` driver + 1. Change log driver to `log_driver =>'file'` from `config/sms.php` Otherwise, if you want more control, you can use the underlying sender object. This will not touch any laravel facade or service provider. @@ -119,7 +123,7 @@ use Xenon\LaravelBDSms\Provider\Ssl; use Xenon\LaravelBDSms\Sender; $sender = Sender::getInstance(); -$sender->setProvider(Ssl::class); +$sender->setProvider(Ssl::class); //change this provider class according to need $sender->setMobile('017XXYYZZAA'); //$sender->setMobile(['017XXYYZZAA','018XXYYZZAA']); $sender->setMessage('helloooooooo boss!'); @@ -145,27 +149,6 @@ array:6 [▼ -------------------------------------------------- -## MimSms - -
-use Xenon\LaravelBDSms\Provider\MimSms; -use Xenon\LaravelBDSms\Sender; - -$sender = Sender::getInstance(); -$sender->setProvider(MimSms::class); -$sender->setMobile('017XXYYZZAA'); -$sender->setMessage('This is test message'); -$sender->setQueue(true); //if you want to sent sms from queue -$sender->setConfig( - [ - 'api_key' => 'api_key_goes_here', - 'type' => 'text', - 'senderid' => 'approved_send_id', - ] -); - -$status = $sender->send(); -## Sms Send Using Custom Gateway We have tried to added most of the gateways of Bangladesh in this package as much as possible. But still if you don't find your expected gateway in this list, then use Custom Gateway using following code snippet. diff --git a/src/Job/SendSmsJob.php b/src/Job/SendSmsJob.php index b7022a4..b98e86c 100644 --- a/src/Job/SendSmsJob.php +++ b/src/Job/SendSmsJob.php @@ -10,6 +10,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Illuminate\Support\Facades\Config; +use Illuminate\Support\Facades\Log as LaravelLog; use JsonException; use Xenon\LaravelBDSms\Facades\Logger; @@ -140,7 +141,12 @@ private function insertLoggerLog(array $log): void { $config = Config::get('sms'); if ($config['sms_log']) { - Logger::createLog($log); + + if ($config['log_driver'] === 'database') { + Logger::createLog($log); + } else if ($config['log_driver'] === 'file') { + LaravelLog::info('laravelbdsms',$log); + } } } diff --git a/src/Sender.php b/src/Sender.php index 2f575c9..ae100aa 100644 --- a/src/Sender.php +++ b/src/Sender.php @@ -15,6 +15,7 @@ use Exception; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\File; +use Illuminate\Support\Facades\Log as LaravelLog; use JsonException; use Xenon\LaravelBDSms\Facades\Logger; use Xenon\LaravelBDSms\Handler\ParameterException; @@ -81,6 +82,9 @@ class Sender | On subsequent runs, it returns the client existing object stored in the static field. This implementation | lets you subclass the Singleton class while keeping just one instance of each subclass around. */ + private array $headers; + private bool $contentTypeJson; + /** * @throws RenderException */ @@ -364,15 +368,28 @@ private function logGenerate($config, $response): void $providerResponse = $object->response; - Logger::createLog([ - 'provider' => get_class($this->provider), - 'request_json' => json_encode([ - 'config' => $config['providers'][get_class($this->provider)], - 'mobile' => $this->getMobile(), - 'message' => $this->getMessage() - ], JSON_THROW_ON_ERROR), - 'response_json' => json_encode($providerResponse, JSON_THROW_ON_ERROR) - ]); + $providerClass = get_class($this->provider); + $requestData = [ + 'config' => $config['providers'][$providerClass], + 'mobile' => $this->getMobile(), + 'message' => $this->getMessage() + ]; + + if ($config['log_driver'] === 'database') { + $logData = [ + 'provider' => $providerClass, + 'request_json' => json_encode($requestData, JSON_THROW_ON_ERROR), + 'response_json' => json_encode($providerResponse, JSON_THROW_ON_ERROR) + ]; + Logger::createLog($logData); + } elseif ($config['log_driver'] === 'file') { + $logData = [ + 'provider' => $providerClass, + 'request_json' => $requestData, + 'response_json' => $providerResponse, + ]; + LaravelLog::info('laravelbdsms', $logData); + } } }