Created
June 20, 2018 12:05
-
-
Save weezqyd/0c6d6c01e885b604c9925187b6ff1f25 to your computer and use it in GitHub Desktop.
Send SMS using Elimuswift SMS package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use App\Invoice; | |
use Elimuswift\SMS\Chennels\SMSChannel; | |
use Elimuswift\SMS\Notifications\SMSMessage; | |
use Illuminate\Notifications\Notification; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
class DueInvoiceReminder extends Notification implements ShouldQueue | |
{ | |
use Queueable; | |
protected $invoice; | |
public function __construct(Invoice $invoice) { | |
$this->invoice = $invoice; | |
} | |
public function via($notifiable) | |
{ | |
return [SMSChannel::class]; | |
} | |
public function toSms($notifiable) | |
{ | |
return (new SMSMessage()) | |
->content("Dear {$notifiable->name} | |
Your account has an oustanding oumount of | |
{$this->invoice->due_amount} please make arrangements to pay this invoice | |
on or before {$this->invoice->due_date}!"); | |
} | |
} | |
// To send this notification all users with a due balance of 500 you need to do this | |
Invoice::where('due_amount', '>', 500)->get()->each(function($invoice) { | |
return $invoice->user->notify(new DueInvoiceReminder($invoice)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment