Laravel + Twilio SMS System Integration in Simple Way
Today, we'll integrate laravel and Twilio SMS system to send SMS from Twilio sms number to another number.
Step 1:
Create Laravel Project called sms-portal
-
composer create-project laravel/laravel sms-portal
Step 2:
Setup database in .env
file - Create a database called - sms_portal
in your MySQL client.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sms_portal
DB_USERNAME=root
DB_PASSWORD=12345678
Step 3:
Run Migration and Start application -
php artisan migrate
php artisan serve
Step 4:
Install and Setup Twilio
Run this command to install twilio PHP sdk.
composer require twilio/sdk
Get twilio credential
from https://console.twilio.com
Set this twilio data in .env
file -
TWILIO_SID="ACxxxxxxxxxxxxxxx"
TWILIO_AUTH_TOKEN="fexxxxxxxxxxxxxxx"
TWILIO_NUMBER="+1xxxxxxxxx"
Step 4:
Create Our Model and Migration to store phone numbers -
php artisan make:model UserPhone -m
It'll create two file - App\Models\UserPhone.php
and databases/migrations/2022_03_19_063150_create_user_phones_table.php
where date time is dynamic for that time in migration file.
Migration File - User Phone Migration
<?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');
}
}
Model File - User Phone 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'
];
}
Create a Controller - HomeController by following command
php artisan make:controller HomeController
HomeController:
Step 6:
Web.php File to Add Routes:
Step 7:
Finally Add Our View File - in welcome.blade.php
Final Output in http://localhost:8000
PHP If-else-elseif and Switch-case
PHP String Functions - All necessary String functions in PHP to manage strings better.
Popular Tutorials
Popular Tutorials
Categories
-
Artificial Intelligence (AI)
11
-
Bash Scripting
1
-
Bootstrap CSS
0
-
C Programming
14
-
C#
0
-
ChatGPT
1
-
Code Editor
2
-
Computer Engineering
3
-
CSS
28
-
Data Structure and Algorithm
18
-
Design Pattern in PHP
2
-
Design Patterns - Clean Code
1
-
E-Book
1
-
Git Commands
1
-
HTML
19
-
Interview Prepration
2
-
Java Programming
0
-
JavaScript
12
-
Laravel PHP Framework
37
-
Mysql
1
-
Node JS
1
-
Online Business
0
-
PHP
28
-
Programming
8
-
Python
12
-
React Js
19
-
React Native
1
-
Redux
2
-
Rust Programming
15
-
SEO - Search Engine Optimization
1
-
Tailwind CSS
1
-
Typescript
10
-
Uncategorized
0
-
Vue JS
1
-
Windows Operating system
1
-
Woocommerce
1
-
WordPress Development
2
Tags
- Artificial Intelligence (AI)
- Bash Scripting
- Business
- C
- C Programming
- C-sharp programming
- C++
- Code Editor
- Computer Engineering
- CSS
- Data Structure and Algorithm
- Database
- Design pattern
- Express JS
- git
- Git Commands
- github
- HTML
- Java
- JavaScript
- Laravel
- Mathematics
- MongoDB
- Mysql
- Node JS
- PHP
- Programming
- Python
- React Js
- Redux
- Rust Programming Language
- SEO
- TypeScript
- Vue JS
- Windows terminal
- Woocommerce
- WordPress
- WordPress Plugin Development