How to send sms notification to mobile phone with laravel 6

Laravel 6 , Laravel

Nicesnippets

949

26-11-2019


hii guys,

In this example,I will show you how to send sms in laravel 6 application.

we will use nexmo package to send sms notification to mobile phone with laravel 6 application.

Follow below step to perform send sms notification to mobile phone in laravel 6 application:

Install Laravel 6

you will create laravel 6 fresh application.

composer create-project --prefer-dist laravel/laravel SendSmsUsingNexmo

Create Nexmo Account

In this step we will create new nexmo account from here : https://www.nexmo.com. then after you will see below screen.

Now, you will get the key and secret from above screen.

Install Package

Run below command in terminal to install nexmo package :

composer require nexmo/client

Create Controller

Type below command to create sms controller :

php artisan make:controller SendSMSController

app/Http/Controllers/SendSMSController.php

update SendSMSController.php file like as below :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class SendSMSController extends Controller

{

public function sendSMS()

{

$basic = new \Nexmo\Client\Credentials\Basic('key', 'secret');

$client = new \Nexmo\Client($basic);

$message = $client->message()->send([

'to' => '9181600*****',

'from' => 'Nexmo',

'text' => 'A text message sent using the Nexmo SMS API'

]);

dd('message send successfully');

}

}

Create Route

Route::get('/send-sms',['as'=>'send.sms','uses'=>'SendSMSController@sendSMS']);

It will help you....