How to send sms notification to mobile phone with laravel 8

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
How to send sms notification to mobile phone with laravel 8

Hello Dev’s Today now in this example,I will show you about how to send sms in laravel 8 application.Here we know How to send sms notification to mobile phone with laravel 8 .

Here we will use nexmo package for sending sms notification to any mobile phone by using laravel 8 application.

For this just need to follow below step to perform send sms notification to any mobile phone in laravel 8 application:

Install Laravel 8

Now we will create laravel 8 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.

How to send sms notification to mobile phone with laravel 8

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

Install Package

Now just run below command in terminal to install nexmo package :

composer require nexmo/client

Create Controller

So now just Type below command to create sms controller :

php artisan make:controller SendSMSController

app/Http/Controllers/SendSMSController.php

Now 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' => '01797*****',
            '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']);

Read Also : How to run laravel project without php artisan serve command ?

Thanks for read. I hope it help you. For more you can follow us on facebook.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →