Created
March 17, 2019 20:25
-
-
Save cjonstrup/bcd8dc381dbaf34c532c7936817ca4f1 to your computer and use it in GitHub Desktop.
Slack - Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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