In Laravel documentation, There is section explained how to make a custom notification class, and the URL is :
So I created a notification class called `MessageReplied', and I want to define a custom SMS channel for it,
In MessageReplied Class, codes are like this:
<?php
namespace App\Notifications;
use App\Channels\SmsChannel;
use App\WorkCase;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class MessageReplied extends Notification
{
use Queueable;
public $workCase;
/**
* Create a new notification instance.
*
* @param WorkCase $workCase
*/
public function __construct(WorkCase $workCase)
{
$this->workCase = $workCase;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database', 'mail', SmsChannel::class];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->markdown('mail.message_replied', ['workCase' => $this->workCase])
->subject('new Message');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'workCase' => $this->workCase
];
}
/**
* @return array
*/
public function toSms()
{
return [
'foo' => 'bar'
];
}
}
and my custom Channel is called SmsChannel and contains:
<?php
namespace App\Channels;
use App\WorkCase;
use GuzzleHttp\Client;
use Illuminate\Notifications\Notification;
use function MongoDB\BSON\toJSON;
class SmsChannel
{
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
public function send($notifiable, Notification $notification)
{
var_dump($notifiable);
$text = !!!How Can I Get this variable from MessageReplied Class ???;
$guzzle = new Client();
$guzzle->post('http://ift.tt/2vxsFnk', [
'form_params' => [
'receptor' => $notification->workCase->client->cellphone,
'message' => $text,
// 'sender' => config('sms.sender')
],
'verify' => false,
]);
}
}
As you see in SmsChannel class how can I get bar
value which is set in MessageReplied Class?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u8lv5B
via IFTTT
Aucun commentaire:
Enregistrer un commentaire