PHP code example of farazsms / laravel

1. Go to this page and download the library: Download farazsms/laravel 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/ */

    

farazsms / laravel example snippets


use FarazSMS\Laravel\Facades\Farazsms;

// Check your balance
$balance = Farazsms::balance();

// Send a pattern (template) message
Farazsms::sendPattern('verify-code', '09120000000', ['code' => '1234']);

// Send a simple text message
Farazsms::sendSimple('سلام دنیا', ['09120000000']);

use Illuminate\Notifications\Notification;
use FarazSMS\Laravel\Notifications\FarazsmsMessage;

class VerifyCodeNotification extends Notification
{
    public function __construct(public string $code)
    {
    }

    public function via($notifiable): array
    {
        return ['farazsms'];
    }

    public function toFarazsms($notifiable): FarazsmsMessage
    {
        return FarazsmsMessage::pattern('verify-code', ['code' => $this->code]);

        // Or a plain text message:
        // return FarazsmsMessage::simple("Your code is {$this->code}");
    }
}

public function routeNotificationForFarazsms($notification): string
{
    return $this->mobile; // or $this->phone
}

$user->notify(new VerifyCodeNotification('1234'));
bash
php artisan vendor:publish --tag=farazsms-config