Как обрабатывать входящие уведомления в Laravel 5.6? - PullRequest
0 голосов
/ 23 ноября 2018

Добрый день,

Я создал модуль уведомлений, целью которого является уведомление администратора при наличии обновлений в github repo.

Что я сделал до сих пор:

  1. Я установил жадность
  2. Установить веб-крючок в github для события push
  3. Реализовать несколько кодов

Вывод: Я получил данные из моего запроса ...

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 [
            //
        ];
    }

Проблема: Чтобы получить уведомление, маршрут должен быть запущен первым.

Чего я хочу добиться: Уведомление в режиме реального времени, при каждом обновлении оно автоматически уведомляет администратораобновления.

Спасибо.

...