laravel-echo-server没有收听所有通知

时间:2018-06-13 08:32:44

标签: laravel laravel-echo laravel-broadcast

我想在我的应用中进行实时通知。我正在使用Laravel广播通知,Laravel Echo和Laravel Echo Server.in我的应用程序在本地通知中监听所有用户但在服务器中如果为5个用户添加通知然后监听2到3个用户,则用户登录保存在laravel.log文件中

代码

//控制器文件

$users = User::whereHas('dealerRoles', function ($query) {
                $query->where('name', DealerRole::DEALERSHIP_DIRECTOR);
                $query->orWhere('name', DealerRole::DEALERSHIP_PRINCIPAL);
                $query->orWhere('name', DealerRole::DEALERSHIP_MANAGER);
            })->whereHas('dealerships', function ($query) use ($listing) {
                $query->where('dealerships.id', $listing->owner_id);
            })->get();

            \Notification::send($users, (new ListingApproved($listing)));

//通知文件(ListingApproved.php)

class ListingApproved extends Notification implements ShouldQueue{
use Queueable;

private $listing;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct(Listing $listing)
{
    $this->listing = $listing;
}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['database', 'broadcast'];
}

public function toArray($notifiable)
{
    return [
        'listing_id' => $this->listing->id,
        'message' => 'Your Listing has been approved Successfully.'
    ];
}

}

// laravel-echo-server.json

{
"authHost": ["http://dealers.cc/", "http://admin.videocarsales.cc/"],
"authEndpoint": "/broadcasting/auth",
"clients": [
    {
        "appId": "31071dab508dc1bb",
        "key": "8262eb7c6589432f457ad25b83d4cb5a"
    }
],
"database": "redis",
"databaseConfig": {
    "redis": {},
    "sqlite": {
        "databasePath": "/database/laravel-echo-server.sqlite"
    }
},
"devMode": true,
"host": null,
"port": "7878",
"protocol": "http",
"socketio": {},
"sslCertPath": "",
"sslKeyPath": "",
"sslCertChainPath": "",
"sslPassphrase": "",
"apiOriginAllow": {
    "allowCors": true,
    "allowOrigin": "http://localhost:80",
    "allowMethods": "GET, POST",
    "allowHeaders": "Origin, Content-Type, X-Auth-Token, X-Requested-With, Accept, Authorization, X-CSRF-TOKEN, X-Socket-Id"
}

}

//听取通知的前端

Echo.private('App.Domain.User.User.' + '{{ auth()->user()->id }}')
            .notification((notification) => {
                console.log('yes');
                Messenger().post({
                    message: 'Your Listing las been approved Successfully.',
                    type: 'success',
                    showCloseButton: true
                });
            });

// laravel.log

[2018-06-13 08:13:09] production.INFO: Broadcasting [Illuminate\Notifications\Events\BroadcastNotificationCreated] on channels [private-App.Domain.User.User.49] with payload:
{
"listing_id": 1,
"message": "Your Listing has been approved Successfully.",
"id": "acb1f428-0116-43a4-88cd-53e35089084a",
"type": "App\\Notifications\\ListingApproved",
"socket": null}

请帮帮我。 提前谢谢!

0 个答案:

没有答案
相关问题