Laravel pusher Illuminate \ Broadcasting \ BroadcastException No message

时光总嘲笑我的痴心妄想 提交于 2019-12-07 23:06:34

问题


I'am using Laravel 5.5 with pusher to make a real time notification , the notification made from the Api
after i made the configuration
in the Api

     public function store(Request $request)
    { 
         $advertising = Advertising::create($request->all()); 
         $admins = \App\Admin::all();
        \Notification::send( $admins, new \App\Notifications\AdvertisingAdded($advertising) );

         return $advertising;
    } 

in AdvertisingAdded

namespace App\Notifications;

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

use Illuminate\Notifications\Messages\BroadcastMessage;
use App\Advertising;

class AdvertisingAdded extends Notification
{
    use Queueable;

    //-must be public fir pusher
    public $advertising;

    public function __construct(Advertising $advertising)
    {
        $this->advertising = $advertising;
    }


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


    public function toArray($notifiable)
    {
        return [
            'msg' => 'Advertising '.$this->advertising->title_ar.' is added ',
            'advertising_id' => $this->advertising->id
        ];
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'msg' => 'Advertising '.$this->advertising->title_ar.' is added ',
            'advertising_id' => $this->advertising->id
        ]);
    }
}

when i post from postman i get an error

Illuminate \ Broadcasting \ BroadcastException No message error image

i followed this video https://www.youtube.com/watch?v=i6Rdkv-DLwk


回答1:


i solve my problem by : making the encrypted: false




回答2:


Add curl options to broadcasting.php

`'pusher' => [
                'driver' => 'pusher',
                'key' => env('PUSHER_APP_KEY'),
                'secret' => env('PUSHER_APP_SECRET'),
                'app_id' => env('PUSHER_APP_ID'),
                'options' => [
                    'cluster' => env('PUSHER_APP_CLUSTER'),
                    'encrypted' => true,
                    'curl_options' => [
                        CURLOPT_SSL_VERIFYHOST => 0,
                        CURLOPT_SSL_VERIFYPEER => 0,
                    ]
                ],`



回答3:


I solved my problem by setting my .env file

Set:

APP_URL=http://localhost
DB_HOST=localhost

And run

php artisan config:cache


来源:https://stackoverflow.com/questions/47990690/laravel-pusher-illuminate-broadcasting-broadcastexception-no-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!