티스토리 뷰
https://medium.com/modulr/send-slack-notifications-with-laravel-8-ff8ad1a6ae61
Send Slack Notifications with Laravel 8
We will learn to send Slack notifications with Laravel 8
medium.com
요기 참고해서 진행하면 된당!
중요부분은 패키지 깔고,
사용하려는 모델에 use Notifiaction; 추가해주고
public function routeNotifiacationForSlack($notification) 메소드 추가해주면 된다
리턴값은 해당 슬랙의 서비스 income 생성한 url을 주면 된다.
config값에 넣어두고 return config('asdf.SLACK_WEBHOOK_URL'); 이런식으로 주고,
config폴더내 asdf 파일에 return [ 'SLACK_WEBHOOK_URL'=>'https://~~~', ]; 에 추가 해줬다.
실제로 사용할때는
// model
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class ToSlack extends Model
{
use HasFactory;
use Notifiable;
protected $table = 'to_slacks';
public function routeNotificationForSlack($notification): string
{
return config('asdf.SLACK_WEBHOOK_URL');
}
}
// notification model
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\SlackMessage;
use Illuminate\Notifications\Notification;
class NotifyToSlack extends Notification
{
use Queueable;
private string $message;
public function __construct(string $message)
{
$this->message = $message;
}
public function via($notifiable)
{
return ['slack'];
}
public function toSlack(): SlackMessage
{
$this->message = '오류 발생. 확인해보셔야합니다!' . $this->message;
return (new SlackMessage())->content($this->message);
}
}
// tinker
>> $message = '이거저거';
>> $slack = App\Models\ToSlack::find(1);
>> $slack->notify(new App\Notifications\NotifyToSlack($message));
슬랙으로 잘 온당!
+. 텔레그램에서 보내기
https://medium.com/modulr/send-telegram-notifications-with-laravel-9-342cc87b406
'Laravel' 카테고리의 다른 글
Failed loading Zend extension 'xdebug' (no such file) (0) | 2023.09.23 |
---|---|
[laravel 8] laravel, php upgrade (0) | 2023.01.27 |
결제 - 아임포트 (0) | 2023.01.11 |
[laravel8] (내기준) 자주 쓰는 콜렉션 메소드를 알아보자. (0) | 2022.11.09 |
[laravel8] $model->unsetRelation() (0) | 2022.11.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 프로그래밍은디버거부터시작이다
- twoseven.kr/0410
- xml로도
- 배열을_이쁘게
- JSON으로도
- gcp
- 테스팅
- twoserven.kr/0410
- Testing
- UTF8
- 테스팅환경
- 엘라스틱서치한글성공!
- fmf
- PhpStorm
- 더미데이터도유형이있어요
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함