Я не знаю, что вы имеете в виду точно, но вот работа класс отправить SMS через plivo
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\User;
use Plivo\RestAPI;
class SendSms implements ShouldQueue
{
use InteractsWithQueue, Queueable, SerializesModels;
protected $sender;
protected $list;
public function __construct($sender,$list)
{
$this->sender = $sender;
$this->list = $list;
$this->from = env('plivo_from');
$this->authid = env('plivo_authid');
$this->token = env('plivo_token');
}
public function handle()
{
$auth_id = $this->authid;
$auth_token = $this->token;
$p = new RestAPI($auth_id, $auth_token);
Send a message
$params = array(
'src' => $this->from, // Sender's phone number with country code
'dst' => $this->list, // receiver's phone number with country code
'text' => 'Hi, Message from Plivo' // Your SMS text message
);
// Send message
$response = $p->send_message($params);
// you can add more code to save error to db or something since this is a job,
}
}
тогда, когда вы хотите отправить смс только
$this->dispatch(new SendSms($sender,$list);
Вы все еще можете сделать это в нормальном классе/функции, но я надеюсь, что у вас есть идея
какая услуга вы используете? –