我正在使用Laravel 5.5和Pusher进行实时通知,通知是从Api发出的 在我完成配置后 在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;
}
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
]);
}
}
当我从邮递员发帖时我收到错误
Illuminate \ Broadcasting \ BroadcastException没有消息 error image
答案 0 :(得分:7)
我通过以下方式解决了我的问题:加密:false
答案 1 :(得分:0)
向curling.php添加curl选项
`'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,
]
],`
答案 2 :(得分:0)
我解决了这个问题。在config / broadcasting.php中使用此代码
'options' => [
'cluster' => 'eu',
'useTLS' => false
],
将useTLS
设置为假
答案 3 :(得分:0)
在 laravel 7 中,像下面这样配置到 config/broadcasting.php 并运行 artisan 命令 cache:clear。为我解决了。
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'mt1',
'useTLS' => false,
],
],
答案 4 :(得分:-1)
我通过设置.env文件解决了问题
设置:
APP_URL=http://localhost
DB_HOST=localhost
然后运行
php artisan config:cache