Slack notification when not configured (example local env) #56375
-
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 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
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 ?) I already wrote a small service class in my project that will check if slack is configured before adding it to via() |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
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.
-
Yes, I wanted only to make sure it is not available. Thank you for the clarification. I'm attaching here my current solution. (not perfect, but works :) its purpose) can sanitize more channels than just slack if you add the options to
can be used like that
|
Beta Was this translation helpful? Give feedback.
Yes, I wanted only to make sure it is not available. Thank you for the clarification.
I'm attaching here my current solution. (not perfect, but works :) its purpose) can sanitize more channels than just slack if you add the options to
canSend()
method