As per the Laravel docs I can do an on-demand notification in a controller like this:
use Notification;
use App\Notifications\TradeSuccessful;
$trada_data = array( 'title' => 'test', 'amount' => 123.45 )
Notification::route('slack', '#test')->notify(new TradeSuccessful($trade_data));
And in TradeSuccessful (example code):
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]
]);
});
}
Main question: when I use Notifications like this (on demand), where do I set the Slack webhook? Because in the documentation they use:
public function routeNotificationForSlack($notification)
{
return 'https://hooks.slack.com/services/...';
}
But that function is defined on a Model, and when using on demand notifications nothing is defined on a Model.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire