Php Lumen如何将变量传递给通知
我正在流明中使用以下插件:Php Lumen如何将变量传递给通知,php,laravel,notifications,lumen,Php,Laravel,Notifications,Lumen,我正在流明中使用以下插件: "illuminate/notifications": "^8.11", "laravel-notification-channels/telegram": "^0.5.0", 在尝试了许多在线可用的示例后,我终于可以发送以下代码集: // App/Console/Command/abc.php namespace App\Console\Commands;
"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));
上面是console命令中的代码,下面是帮助文件:
// 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。
如果我使用任何在线可用的插件示例,它就是不起作用。谁能给点建议吗?谢谢在
构造方法中发送您的参数:
类TGNotification扩展了通知
{
受保护$tg;
公共功能结构($tg)
{
$this->tg=$tg;
}
}
或者,您可以使用setter和getter方法。我认为
$tg
应该是受保护的函数