use GrantHolle\Notifications\Channels\AliyunSmsChannel;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
if (!app()->environment('production')) {
AliyunSmsChannel::alwaysTo('your-phone-number');
}
}
}
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use GrantHolle\Notifications\Messages\AliyunMessage;
use App\Order;
class OrderPaid extends Notification
{
protected $order;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['aliyun'];
}
/**
* Get the Aliyun SMS representation of the notification.
*
* @param mixed $notifiable
* @return \GrantHolle\Notifications\Messages\AliyunMessage
*/
public function toAliyunSms($notifiable)
{
return (new AliyunMessage)
->template('SMS_XXXXXXX')
->data([
'order_no' => $this->order->order_no,
'total' => $this->order->total,
]);
}
}
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the Aliyun SMS channel.
*
* @param \Illuminate\Notifications\Notification $notification
* @return string
*/
public function routeNotificationForAliyun($notification)
{
return $this->phone;
}
}
use App\Notifications\OrderPaid;
$user->notify(new OrderPaid($order));
bash
php artisan make:notification OrderPaid
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.