<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aybimyazilim / dataport-sms-notification example snippets
namespace App\Notifications;
use AybimYazilim\DataPortSms\Notifications\DataPortSmsNotification;
class OrderConfirmation extends DataPortSmsNotification
{
private $order;
public function __construct($order)
{
$this->order = $order;
}
public function toDataPortSms($notifiable): array
{
return [
'text' => "Siparişiniz #{$this->order->id} onaylandı!",
'phone' => $notifiable->phone, // Opsiyonel
];
}
}
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
class OrderConfirmation extends Notification implements ShouldQueue
{
use Queueable;
private $order;
public function __construct($order)
{
$this->order = $order;
}
public function via($notifiable)
{
return ['dataport-sms'];
}
public function toDataPortSms($notifiable): array
{
return [
'text' => "Siparişiniz #{$this->order->id} onaylandı! Toplam: {$this->order->total}₺",
'phone' => $notifiable->phone, // Opsiyonel
];
}
}
// User model üzerinden
$user = User::find(1);
$user->notify(new OrderConfirmation($order));
// Notification facade ile
use Illuminate\Support\Facades\Notification;
Notification::send($users, new OrderConfirmation($order));
// Belirli bir telefon numarasına
Notification::route('dataport-sms', '905551234567')
->notify(new OrderConfirmation($order));
class User extends Authenticatable
{
// Telefon numarası için özel routing
public function routeNotificationForDataPortSms()
{
return $this->phone_number;
}
// Veya telefon alanı için accessor
public function getPhoneAttribute()
{
return $this->mobile ?? $this->telephone;
}
// SMS loglarına erişim
public function smsLogs()
{
return $this->morphMany(SmsLog::class, 'notifiable');
}
}
use AybimYazilim\DataPortSms\Messages\DataPortSmsMessage;
public function toDataPortSms($notifiable): array
{
return (new DataPortSmsMessage('Mesaj içeriği'))
->to('905551234567')
->toArray();
}
// Queue konfigürasyonu
public function __construct($order)
{
$this->order = $order;
$this->onQueue('sms'); // Özel queue
$this->delay(now()->addMinutes(5)); // Gecikme
}
use AybimYazilim\DataPortSms\Tests\TestCase;
use Illuminate\Support\Facades\Http;
class MyNotificationTest extends TestCase
{
/** @test */
public function it_sends_sms_notification()
{
Http::fake([
'api.dataport.com.tr/*' => Http::response(['success' => true])
]);
$user = new User(['phone' => '905551234567']);
$user->notify(new MyNotification());
Http::assertSent(function ($request) {
return str_contains($request->url(), 'dataport.com.tr');
});
}
}