Я не могу вернуть данные на консоль с помощью пушера - PullRequest
0 голосов
/ 28 марта 2020

все выглядит идеально в терминале данные были получены через веб-сокет

, но когда я пытаюсь вернуть данные в консоль браузера, чтобы их можно было отобразить в проекте с vue через уведомления с laravel -echo, я не получаю никаких данных в консоли браузера, только отображается в Ma c терминал

Это мой код App \ Notifications \ newFriendRequest;

<?php

namespace App\Notifications;

use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\BroadcastMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class newFriendRequest extends Notification
{
    use Queueable;

    public function __construct()
    {
        //
    }

    public function via($notifiable)
    {
        return ['database','broadcast'];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    public function toDatabase($notifiable)
    {
        return [
            'userid' => auth()->user()->id,
            'username' => auth()->user()->username,
            'avatar' => auth()->user()->avatar,
            'status' => 'FRIEND_REQUEST_RECEIVED',
            'type' => 'FRIEND_REQUEST',
        ];
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'userid' => auth()->user()->id,
            'username' => auth()->user()->username,
            'avatar' => auth()->user()->avatar,
            'status' => 'FRIEND_REQUEST_RECEIVED',
            'type' => 'FRIEND_REQUEST',
        ]);
    }

    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}

и vue код

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '******',
    wsHost: window.location.hostname,
    wsPort: 6001,
    cluster: 'us2',
    forceTLS: true
});

...

mounted() {
            //Catch the request friend status
            this.getStatus(this.userprofile.id);
            //console.log(this.userprofile.id);

            Echo.private('App.User.' + this.user.id)
                .notification((data) => {
                    console.log(data);
                });
        },

и маршруты / API. php

Route::group(['middleware' => 'auth:api'], function () {
    Route::get('/user', function (Request $request) {
        return $request->user();
    });
});
``
...