1. Go to this page and download the library: Download rayzenai/laravel-sms 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/ */
rayzenai / laravel-sms example snippets
// config/laravel-sms.php
'user_model' => [
'enabled' => true,
'class' => \App\Models\User::class,
'phone_field' => 'phone', // The field that contains the phone number
'name_field' => 'name', // The field to display as user name
],
'phone' => '
use Rayzenai\LaravelSms\Services\SmsService;
use Rayzenai\LaravelSms\Facades\Sms;
// Method 1: Using the Facade with fluent interface (recommended)
$sentMessage = Sms::to('+9779801002468')
->message('Hello from Laravel SMS!')
->send();
// Method 2: Using the Facade with direct method call
$sentMessage = Sms::send('+9779801002468', 'Hello from Laravel SMS!');
// Method 3: Using dependency injection
public function sendSms(SmsService $smsService)
{
try {
$sentMessage = $smsService->send('+1234567890', 'Hello from Laravel SMS!');
// Access sent message details
echo "Message ID: " . $sentMessage->provider_message_id;
echo "Status: " . $sentMessage->status;
} catch (\Exception $e) {
// Handle error
Log::error('SMS sending failed: ' . $e->getMessage());
}
}
// Method 3: Using service container
$smsService = app(SmsService::class);
$sentMessage = $smsService->send('+1234567890', 'Your message here');
use Rayzenai\LaravelSms\Facades\Sms;
use Rayzenai\LaravelSms\Services\SmsService;
// Method 1: Using the Facade with fluent interface (recommended)
$recipients = [
'+9779801002468',
'+9779812345678',
'+9779898765432'
];
$sentMessages = Sms::to($recipients)
->message('Bulk message to all recipients!')
->sendBulk();
// Method 2: Using the service directly
$smsService = app(SmsService::class);
try {
$sentMessages = $smsService->sendBulk($recipients, 'Bulk message to all recipients!');
foreach ($sentMessages as $message) {
echo "Recipient: {$message->recipient} - Status: {$message->status}\n";
}
} catch (\Exception $e) {
Log::error('Bulk SMS failed: ' . $e->getMessage());
use Illuminate\Foundation\Auth\User as Authenticatable;
use Rayzenai\LaravelSms\Concerns\Smsable;
use Rayzenai\LaravelSms\Contracts\HasSmsNumber;
class User extends Authenticatable implements HasSmsNumber
{
use Smsable;
public function smsPhoneNumber(): ?string
{
// Return a sendable number (E.164 like +9779801002468 recommended),
// or null if this user can't be reached by SMS.
return $this->phone;
// e.g. concat: '+' . ltrim($this->country_code, '+') . $this->phone
}
}
// Straight off the model — returns a SentMessage, or null if it has no number
$user->sendSMS('Your appointment is confirmed.');
// Send via a specific provider
$user->sendSMS('Sent via AakashSMS', 'aakash');
// Through the facade — models and plain strings can be mixed
Sms::to($user)->message('Hi')->send();
Sms::to($users)->message('Clinic closed tomorrow')->sendBulk();
use Rayzenai\LaravelSms\Facades\Sms;
// Send this one message through AakashSMS regardless of the default provider
Sms::provider('aakash')->send('+9779801002468', 'Sent via AakashSMS');
Sms::provider('swift')
->to(['+9779801002468', '+9779812345678'])
->message('Sent via SwiftSMS')
->sendBulk();
use Rayzenai\LaravelSms\LaravelSmsPlugin;
// In app/Providers/Filament/AdminPanelProvider.php or your panel provider:
public function panel(Panel $panel): Panel
{
return $panel
->default()
->plugins([
LaravelSmsPlugin::make(),
]);
}