[英]Lumen how to pass variable to notification
我在流明中使用以下插件:
"illuminate/notifications": "^8.11",
"laravel-notification-channels/telegram": "^0.5.0",
在嘗試了許多在線可用的示例后,最后我可以發送以下代碼集:
// App/Console/Command/abc.php
namespace App\Console\Commands;
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;
use Illuminate\Support\Facades\Notification;
use App\Helpers\TGNotification;
Notification::route(TelegramChannel::class, '-123456')
->notify(new TGNotification($tg));
上面是控制台命令中的代碼,下面是一個幫助文件:
// App/Helpers/TGNotification.php
namespace App\Helpers;
use NotificationChannels\Telegram\TelegramChannel;
use NotificationChannels\Telegram\TelegramMessage;
use Illuminate\Notifications\Notification;
class TGNotification extends Notification
{
public function via($notifiable)
{
return [TelegramChannel::class];
}
public function toTelegram($notifiable)
{
$url = "http://www.google.com";
return TelegramMessage::create()
// Optional recipient user id.
// ->to($notifiable->telegram_user_id)
->to("-123456")
// Markdown supported.
->content($notifiable->msg)
// (Optional) Blade template for the content.
// ->view('notification', ['url' => $url])
// (Optional) Inline Buttons
->button('Hello', $url)
->button('World', $url);
}
}
但是,我無法將變量從 abc.php 傳遞到 TGNotification.php。 如果我使用在線提供的此插件的任何示例,它就不起作用。 任何人都可以請指教嗎? 謝謝
在construct
方法中發送您的參數:
class TGNotification extends Notification
{
protected $tg;
public function __construct($tg)
{
$this->tg = $tg;
}
}
或者,您可以使用 setter 和 getter 方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.