masrur447/twilio-sdk

Laravel integration for Twilio SDK

1.0.0 2025-07-27 07:10 UTC

This package is auto-updated.

Last update: 2025-07-27 07:17:55 UTC


README

A simple Laravel package that provides an elegant wrapper for sending SMS using the Twilio API.

Developed by Masrur

๐Ÿš€ Features

  • Easy Twilio integration in Laravel
  • Simple API to send SMS
  • Configuration via .env file

๐Ÿงฑ Requirements

  • PHP 8.2 or higher
  • Laravel 12x
  • Twilio Account & Credentials

๐Ÿ“ฆ Installation

Install the package via Composer:

composer require masrur447/twilio-sdk

โš™๏ธ Configuration

Step 1: Publish the config file

php artisan vendor:publish --tag=twilio-config

This will publish the config file to:

config/twilio.php

Step 2: Add your credentials in .env

TWILIO_SID=your_twilio_account_sid
TWILIO_TOKEN=your_twilio_auth_token
TWILIO_SENDER_NUMBER=your_twilio_whatsapp_sender_number
TWILIO_SMS_NUMBER=your_twilio_sms_sender_number

Step 3: Example of config/twilio-sdk.php

return [
    'account_sid' => env('TWILIO_SID', ''),
    'auth_token' => env('TWILIO_TOKEN', ''),
    'wp_sender' => env('TWILIO_SENDER_NUMBER', ''),
    'sms_sender' => env('TWILIO_SMS_NUMBER', ''),
];

๐Ÿ“ค Usage

โœ… Send Whatsapp Message

use Masrur447\TwilioSdk\Twilio;

Twilio::sendWP('+8801234567890', 'Hello from Laravel Twilio SDK!', 'media url or null');

โœ… Send SMS

use Masrur447\TwilioSdk\Twilio;

Twilio::sendSMS('+8801234567890', 'Hello from Laravel Twilio SDK!');

๐Ÿงช Easy way to use it just add trait in user model

use InteractsWithTwilio;

$user = User::find(1);
$user->notifyTwilioWhatsapp('Hellow from Laravel trait Twilio SDK', 'media url or null');
$user->notifyTwilioSMS('Hellow from Laravel trait Twilio SDK');

๐Ÿงช Example: Sending SMS from Controller

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Masrur447\TwilioSdk\Twilio;

class SmsController extends Controller
{
    public function send(Request $request)
    {
        Twilio::sendSMS($request->phone, $request->message);

        return response()->json([
            'status' => 'SMS sent successfully!',
        ]);
    }
}

๐Ÿงช Example: Tinker Usage

php artisan tinker
>>> Twilio::sendSMS('+8801234567890', 'Test SMS from tinker');

๐Ÿ›  Advanced Usage (Optional)

Coming soon...

๐Ÿค Contributing

Contributions, issues, and feature requests are welcome!
Feel free to check issues page if you want to contribute.

๐Ÿงพ License

This project is open-sourced under the MIT license.
See the LICENSE file for more information.

๐Ÿ™Œ Author

Masrur โ€” GitHub

๐ŸŒŸ Show your support

If you like this package, give it a โญ on the GitHub repo!