Php Laravel Slack按需通知;在哪里设置webhook?
根据Laravel文档,我可以在控制器中执行按需通知,如下所示:Php Laravel Slack按需通知;在哪里设置webhook?,php,laravel,laravel-5,slack,laravel-5.8,Php,Laravel,Laravel 5,Slack,Laravel 5.8,根据Laravel文档,我可以在控制器中执行按需通知,如下所示: use Notification; use App\Notifications\TradeSuccessful; $trada_data = array( 'title' => 'test', 'amount' => 123.45 ) Notification::route('slack', '#test')->notify(new TradeSuccessful($trade_data)); 在Trade
use Notification;
use App\Notifications\TradeSuccessful;
$trada_data = array( 'title' => 'test', 'amount' => 123.45 )
Notification::route('slack', '#test')->notify(new TradeSuccessful($trade_data));
在TradeSuccessful
(示例代码)中:
主要问题:
当我使用这样的通知(按需)时,我应该在哪里设置Slack webhook?因为在他们使用的文档中:
public function routeNotificationForSlack($notification)
{
return 'https://hooks.slack.com/services/...';
}
但该功能是在模型上定义的,当使用按需通知时,模型上没有定义任何内容。来自:
按需通知
有时,您可能需要向未收到通知的人发送通知
存储为应用程序的“用户”。使用
Notification::route
方法,您可以指定特别通知
发送通知前的路由信息:
Notification::route('mail', 'taylor@example.com')
->route('nexmo', '5555555555')
->notify(new InvoicePaid($invoice));
在松弛的情况下,您指定的管线需要是腹板挂钩:
use Notification;
use App\Notifications\TradeSuccessful;
$trada_data = array( 'title' => 'test', 'amount' => 123.45 );
$slack_webhook = 'my-slack-webhook-url'; // <---
Notification::route('slack', $slack_webhook)->notify(new TradeSuccessful($trade_data));
^^^^^^^^^^^^^^
使用通知;
使用App\Notifications\TradeSuccessful;
$trada_data=数组('title'=>test','amount'=>123.45);
$slack_webhook='my slack webhook url';//通知(新交易成功($trade_data));
^^^^^^^^^^^^^^
当然,您应该将is存储为
env()
键,但是您知道了。在通知类中,您如何使用($trade\u data)
?我没有看到任何地方申报。尝试此操作时,传入的数据也不会出现在$notifiable
变量中。
use Notification;
use App\Notifications\TradeSuccessful;
$trada_data = array( 'title' => 'test', 'amount' => 123.45 );
$slack_webhook = 'my-slack-webhook-url'; // <---
Notification::route('slack', $slack_webhook)->notify(new TradeSuccessful($trade_data));
^^^^^^^^^^^^^^