Slack notification when not configured (example local env) #56375
Unanswered
abdel-aouby
asked this question in
Q&A
Replies: 1 comment
-
Hi 👋 Yes, this is a common scenario in development environments. Since the You're doing the right thing by checking if Slack is configured before adding it to the One way to handle it globally could be using a base notification class like this: public function via($notifiable)
{
$via = ['mail'];
if (
app()->environment('production') &&
config('services.slack.token') &&
config('services.slack.channel')
) {
$via[] = 'slack';
}
return $via;
}
Or even better, create a helper function like slackIsConfigured() and reuse that logic across multiple notifications.
Laravel doesn't yet provide built-in filtering like preventSilentlyDiscardingAttributes() for notifications, so your approach is reasonable.
Would be great if Laravel supported a native way to skip unconfigured channels based on environment flags.
Thanks for raising this! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I have a situation and I would like to ask the community to see if it's an issue specific to my project or if it's by design.
If i have a notification class with 2 methods
and
via(object $notifiable)
method returns['mail', 'slack']
This works fine and well tested, when i set the env config to good values
but let's say i don't want to keep sending the slack notification when i'm on DEV env, so i removed the config values form my
.env
file in local machine (expecting to receive only the mails and the slack will be ignored)but not, the notification class is always throwing an error
[2025-07-22 13:17:30] local.ERROR: Slack notification channel is not set. {"exception":"[object] (LogicException(code: 0): Slack notification channel is not set. at /var/www/html/vendor/laravel/slack-notification-channel/src/Slack/SlackChannel.php:44)
is this by desing? or it needs somehow to be managed better, because many projects don't need to send the slack notifications other than production env?
Yes it does make sense to fail if slack if not configured but i think we could add some global flag that will not send slack notification under some condition (not prod env ?)
similar to the ones we have for model
Model::preventSilentlyDiscardingAttributes($this->app->isLocal());
I already wrote a small service class in my project that will check if slack is configured before adding it to via()
but i would like to hear your idea about it. and if there is not a build in laravel functionality that manage this
Beta Was this translation helpful? Give feedback.
All reactions