1. Go to this page and download the library: Download misaf/laravel-sms-gateway library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Misaf\LaravelSmsGateway\Events\SmsSent;
final class StoreSmsGatewayResult
{
public function handle(SmsSent $event): void
{
$driver = $event->driverName;
$url = $event->request->url();
$status = $event->response->status();
$body = $event->response->json();
}
}
namespace App\SmsGateways;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response;
use Misaf\LaravelSmsGateway\SmsGatewayDriver;
final class CustomDriver extends SmsGatewayDriver
{
/**
* @param array<string, mixed> $data
*/
public function send(array $data): Response
{
return $this->request()->post('messages', $data);
}
protected function defaultBaseUrl(): string
{
return 'https://api.example.com';
}
protected function configureRequest(PendingRequest $request): PendingRequest
{
return $request->withToken($this->driverConfig('token'));
}
}
use App\SmsGateways\CustomDriver;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\ServiceProvider;
use Misaf\LaravelSmsGateway\Facade\SmsGateway;
final class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
SmsGateway::extend('custom', function (Application $app): CustomDriver {
return $app->make(CustomDriver::class);
});
}
}