Hi guys,
Let's Integrate Twilio with our Laravel application easily with some few steps.
Step-1: Create a Laravel Project called - sms-portal
.
composer create-project laravel/laravel sms-portal
Step-2: Configure .env file - After creating the database sms_portal
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sms_portal
DB_USERNAME=root
DB_PASSWORD=12345678
Step-3: Start Server
php artisan migrate
php artisan serve
Step-4: Install Twilio PHP SDK
composer require twilio/sdk
Step-5: Get Twilio credential
Go to https://console.twilio.com
Check their your Account SID, Auth Token and Twiolio Phone Number.
Set this value in .env
File -
TWILIO_SID="ACxxxxxxxxxxxxxxx"
TWILIO_AUTH_TOKEN="fexxxxxxxxxxxxxxx"
TWILIO_NUMBER="+1xxxxxxxxx"
Step-6: Create Our UserPhone model
Using this model we'll send message to these phone number from our registered Twilio Phone number.
php artisan make:model UserPhone -m
In CreateUserPhonesTable
migration - only add the phone_number
string column.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUserPhonesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_phones', function (Blueprint $table) {
$table->id();
$table->string('phone_number');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_phones');
}
}
In UserPhone
model -
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserPhone extends Model
{
use HasFactory;
protected $table = 'user_phones';
protected $fillable = [
'phone_number'
];
}
For More, Please Read Full Article in DevsEnv - https://devsenv.com/tutorials/laravel-+-twilio-sms-system-integration-in-simple-way
Our Final application will be look like this -
Top comments (0)