![]() ![]() You'll also need to make sure that your model is using the Illuminate\Notifications\Notifiable trait so that we can use the notify method to send the notification later. Public function routeNotificationForVonage($notification) Use Illuminate\Foundation\Auth\User as Authenticatable For example, we could update our model to look like so: namespace App\Models So, we create a new routeNotificationForVonage method on our User model that returns the phone_number field. At the moment, it has no idea which phone number to use. Whenever we send an SMS notification in Laravel, we need to let Laravel know where to grab the recipient's phone number from. In this example, we're going to imagine that we want to send the SMS to our User models and that they have their phone number stored in a phone_number field. Now that we have the notification channel set up, we need to configure our model. ![]() ![]() Further down, we'll discuss how you can override this value on a notification-by-notification basis when sending the SMS messages. If you've bought a phone number from Vonage, you may want to put that number here or you might want to use your brand/company name here instead. This will be the number (or name) that the message will appear as being sent by. env file and add our API keys that we got after creating our Vonage account: VONAGE_KEY=your-vonage-key-hereĪs you can see, we've also added a VONAGE_SMS_FROM field too. Now that we've created our Vonage account and got our API keys, we can install Laravel's first-party notification channel for Vonage ( laravel/vonage-notification-channel) using the following command: composer require laravel/vonage-notification-channel Once you're ready to use Vonage and lift the restrictions, you can upgrade to a paid account. You'll only be able to send the message to your own phone numberīut, this isn't an issue because it can give you a chance to experiment with the API and check whether its right for your project.All of the SMS messages that you send will have a watermark at the end of the message (which says "").When you first sign up, you'll likely be given some free credit (I was given €2 EUR) and have some small restrictions placed on your account, such as: It's super simple and quick to do! After that, you'll be able to grab your API keys. Sending SMS Using Vonage Create a Vonage Accountīefore we touch any code in our projects, you'll first need to create a Vonage account. In this particular guide, we'll be using the SMS API. Verify API - for adding 2FA functionality and verifying a user's phone number or identity.SMS API - for sending and receiving SMS.Vonage offers several different APIs that you can use, including: ![]() In this guide, we're going to take a look at how to use Vonage (who were previously named Nexmo) to send an SMS message to your users from your Laravel app. To send the messages, you'll typically need to interact with a third-party service's API (such as Vonage or Twilio) that can handle the sending (and sometimes receiving) of your messages. You might want to do this to send notifications to your users, or maybe as a form of 2FA (two factor authentication). In your Laravel applications, there may be times that you want to send SMS messages to your users. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |