【问题标题】:Laravel pusher not authenticated in Localhost but authenticated in Development ServerLaravel 推送器未在 Localhost 中进行身份验证,但在 Development Server 中进行了身份验证
【发布时间】:2021-10-23 02:14:24
【问题描述】:

我刚刚在私人频道中使用推送器设置了我的 Laravel 通知。开发服务器(127.0.0.1:8000)上一切正常。我经常收到通知,但是当我尝试从 localhost(http://localhost/) 运行时出现身份验证错误“http://localhost/broadcasting/auth 404 not found”。这是我的代码:

Reportnotification.php

public function toArray($notifiable)
{
    return [
        'message'=>$this->details,
        'link'=> $this->link,
    ];
}

public function toBroadcast($notifiable): BroadcastMessage
{
    return new BroadcastMessage([
        'message' => "$this->details",
        'link'=> "$this->link"
    ]);
}

事件/报告通知

class ReportNotification implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;
    // public $username;
    public $message;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($message)
    {

        $message = $this->message;
 

   }

/**
 * Get the channels the event should broadcast on.
 *
 * @return \Illuminate\Broadcasting\Channel|array
 */
public function broadcastOn()
{
  
 return new PrivateChannel('notification');
}

监听器/SendReportNotification

public function handle($event)
{
    $admins = User::where('role',1)->get();
    ReportNotification::send($admins, new ReportNotification($event->user));
}

Channels.php

Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;

});

ma​​ster.blade.php

<script>
        var id = {{Auth::user()->id}}
        Echo.private('App.Models.User.'+id)
        .notification((ReportNotification) => {
            console.log(ReportNotification.message);
            console.log(ReportNotification.link);
        });

    </script>

这些是我的代码。在 "127.0.0.1:8000" 中一切正常,但在 "localhost"

中无法正常工作

【问题讨论】:

    标签: php laravel push-notification pusher


    【解决方案1】:

    localhost 名称通常解析为 127.0.0.1

    当您打开http://localhost 时,它会解析127.0.0.1:80,因为80 是HTTP 协议的默认端口号。

    如您所说,您的服务器正在收听8000。所以你应该改用localhost:8000 或者将你的网络服务器使用的端口更改为80

    【讨论】:

      猜你喜欢
      • 2015-09-23
      • 2020-11-05
      • 2021-02-08
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多