美好的一天,
我创建了一个通知模块,目的是在github存储库中有更新时通知管理员。
我到目前为止所做的事情:
输出:我收到了请求中的数据...
Route::get('hook',function(){
$client = new \GuzzleHttp\Client();
$response = $client->request('GET', 'https://api.github.com/repos/user/learning-laravel');
$data = json_decode($response->getBody()->getContents(),true);
// dd($data);
if(auth()->user()->hasRole('admin')){
$this->notify(new \App\Notifications\WebhookNotification($data));
}
return view('pages.admin.system.webhook.index')->with(['data' => $data]);
});
Route::get('/markAsRead',function(){
auth()->user()->unreadNotifications->markAsRead();
return redirect('iaccs-hook-list');
})->name('markRead');
这是我的WebhookNotification.php
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
// return ['mail'];
return ['database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
// public function toMail($notifiable)
// {
// return (new MailMessage)
// ->line('The introduction to the notification.')
// ->action('Notification Action', url('/'))
// ->line('Thank you for using our application!');
// }
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
//
];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
问题:要获取通知,应首先触发该路线。
我要实现的目标:实时通知,每次有更新时,都会自动将更新通知管理员。
谢谢。