PHP code example of mcbankske / filament-sms-notifier
1. Go to this page and download the library: Download mcbankske/filament-sms-notifier 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/ */
mcbankske / filament-sms-notifier example snippets
use MCBANKSKE\FilamentSmsNotifier\Facades\SmsNotifier;
// Send an SMS
$response = SmsNotifier::send('254700000000', 'Hello from Filament SMS Notifier!');
if ($response['success']) {
// SMS sent successfully
} else {
// Handle error
logger()->error('Failed to send SMS: ' . $response['message']);
}
// Send an SMS using the helper function
$response = sms('254700000000', 'Hello from the helper function!');
if ($response['success']) {
// SMS sent successfully
} else {
// Handle error
logger()->error('Failed to send SMS: ' . $response['message']);
}
use MCBANKSKE\FilamentSmsNotifier\Services\SmsService;
public function sendWelcomeSms(SmsService $smsService)
{
$phoneNumber = '254700000000'; // E.164 format
$message = 'Welcome to our service!';
$response = $smsService->send($phoneNumber, $message);
if ($response['success']) {
// SMS sent successfully
} else {
// Handle error
logger()->error('Failed to send SMS: ' . $response['message']);
}
}
use MCBANKSKE\FilamentSmsNotifier\Filament\Widgets\SendTestSmsWidget;
protected function getHeaderWidgets(): array
{
return [
SendTestSmsWidget::class,
];
}
namespace App\SmsDrivers;
use MCBANKSKE\FilamentSmsNotifier\Contracts\SmsGatewayDriver;
class MyCustomDriver implements SmsGatewayDriver
{
public function send(string $to, string $message): array
{
// Your implementation here
return [
'success' => true,
'message' => 'SMS sent successfully',
'data' => [/* response data */]
];
}
}
use App\SmsDrivers\MyCustomDriver;
use MCBANKSKE\FilamentSmsNotifier\Services\SmsService;
public function boot()
{
app()->when(MyCustomDriver::class)
->needs('$config')
->giveConfig('smsnotifier.drivers.my-custom');
app(SmsService::class)->extend('my-custom', function ($app) {
return new MyCustomDriver(config('smsnotifier.drivers.my-custom'));
});
}