Skip to content

Instantly share code, notes, and snippets.

@cjonstrup
Created March 17, 2019 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjonstrup/bcd8dc381dbaf34c532c7936817ca4f1 to your computer and use it in GitHub Desktop.
Save cjonstrup/bcd8dc381dbaf34c532c7936817ca4f1 to your computer and use it in GitHub Desktop.
Slack - Laravel
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
const SLACK_CHANNEL_WWW = 'xxx';
const SLACK_CHANNEL_BACKEND = 'xxx';
protected $slackChannels= [
self::SLACK_CHANNEL_WWW,
self::SLACK_CHANNEL_BACKEND,
];
protected $slack_url = null;
/**
* Specify Slack Webhook URL to route notifications to
*
* @return string
*/
public function routeNotificationForSlack(){
if($this->slack_url === null){
return self::SLACK_CHANNEL_WWW;
}
return $this->slack_url;
}
/**
* @param $name
* @return $this
*/
public function setSlackChannel($name){
if(in_array($name, $this->slackChannels)){
$this->setSlackUrl($name);
}
return $this;
}
/**
* @param $url
* @return $this
*/
public function setSlackUrl($url){
$this->slack_url = $url;
return $this;
}
}
// $user = User::find(1);
// $user->setSlackChannel(User::SLACK_CHANNEL_WWW)->notify(new ShopCreated());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment