Laravel Slack 点播通知;在哪里设置网络钩子?

Laravel Slack on-demand notification; where to set the webhook?

根据 Laravel 文档,我可以像这样在控制器中执行按需通知:

use Notification;
use App\Notifications\TradeSuccessful;

$trada_data = array( 'title' => 'test', 'amount' => 123.45 )

Notification::route('slack', '#test')->notify(new TradeSuccessful($trade_data));

并且在TradeSuccessful(示例代码)中:

public function toSlack($notifiable)
    {
        return (new SlackMessage)
            ->success()
            ->content('One of your invoices has been paid!')
            ->attachment(function ($attachment) use ($trade_data) {
                $attachment->title('Invoice 1322')
                    ->fields([
                    'Title' => $trade_data['title],
                    'Amount' => $trade_data['amount]
                ]);
            });
    }

主要问题: 当我使用这样的通知(按需)时,我应该在哪里设置 Slack webhook?因为在他们使用的文档中:

public function routeNotificationForSlack($notification)
    {
        return 'https://hooks.slack.com/services/...';
    }

但是该函数是在模型上定义的,当使用按需通知时,模型上没有任何定义。

来自documentation

On-Demand Notifications

Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the Notification::route method, you may specify ad-hoc notification routing information before sending the notification:

Notification::route('mail', 'taylor@example.com')
            ->route('nexmo', '5555555555')
            ->notify(new InvoicePaid($invoice));

对于 Slack,您指定的路由需要是 web-hook:

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));
                             ^^^^^^^^^^^^^^

当然,您应该将 is 存储为 env() 键,但您明白了。