PHP code example of akibatech / laravel-ovh-sms

1. Go to this page and download the library: Download akibatech/laravel-ovh-sms library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

akibatech / laravel-ovh-sms example snippets


Akibatech\Ovhsms\ServiceProvider::class,

'Ovhsms' => Akibatech\Ovhsms\Facade::class,

Ovhsms::sendMessage('+33611223344', 'Hello!');

public function myControllerAction(Akibatech\Ovhsms\OvhSms $client)
{
    $client->sendMessage('+33611223344', 'Hello!');
}

$client = app('ovhsms');

// Prepare a new SMS instance and return it.
$sms = $client->newMessage('the phone number');
$sms->send('Hi!');

// Same as above but the SMS is marked as a marketing message.
$sms = $client->newMarketingMessage($phone); // Alias of newMessage($phone, true);
$sms->send('Hello!');

// Attach many receivers
$sms = $client->newMessage(['phone1', 'phone2'], ...);
$sms->send('Hi guys!');

// Send directly the message
$client->sendMessage($phone, 'Hello!');
// Or
$client->sendMarketingMessage($phone, 'Super price this sunday!');

// Retrieve OVH SMS instance
$ovhsms = app('ovhsms'); // Or Ovhsms::getClient();

// Get available SMS accounts
$accounts = $ovhsms->getAccounts();

// Set the account you will use
$ovhsms->setAccount($accounts[0]);

// Create a new message that will allow the recipient to answer (to FR receipients only)
$sms = $ovh->createMessage(true);
$sms->addReceiver("+33601020304");
$sms->setIsMarketing(false);

// Plan to send it in the future
$sms->setDeliveryDate(new DateTime("2018-02-25 18:40:00"));
$sms->send("Hello world!");

namespace App\Notifications;

use Akibatech\Ovhsms\Notifications\OvhSmsChannel;
use Akibatech\Ovhsms\Notifications\OvhSmsMessage;
use Illuminate\Notifications\Notification;

class ExampleNotification extends Notification
{
    /**
     * Notification via OvhSmsChannel.
     */
    public function via($notifiable)
    {
        return [OvhSmsChannel::class];
    }

    /**
     * Your notification must implements "toOvh()"
     */
    public function toOvh($notifiable)
    {
    	return (new OvhSmsMessage('A new invoice was paid! Amount: $9.00'));
    }
}

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    
    /**
     * Returns the user's phone number.
     */
    public function routeNotificationForOvh()
    {
        return $this->phone; // Ex: +33611223344
    }
}
bash
php artisan vendor:publish --provider="Akibatech\Ovhsms\ServiceProvider"