Laravel - 导致 404 错误的事件

Laravel - Event causing 404 error

我在制作实时通知的过程中遇到了这个奇怪的错误。我的模型中有一个启动方法,它触发一个名为 SendNotificationData 的事件(无侦听器)。它在发出新通知时进行处理。

试用控制器

<?php

namespace App\Http\Controllers\Notification;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Models\Notification;

class NotificationController extends Controller
{  
    /**
     * Trigger event to display notifications. This displays 404 error page
     *
     * @return none
     */
    public function displayNotification()
    {
        $notification = new Notification();
        $notification->EmployeeID = "EMP-00001";
        $notification->NotificationText =  "There is a new notification";
        $notification->NotificationStatus = "unread";
        $notification->NotificationType = "trial";
        $notification->save();
    }
}

通知模型启动方式:

/**
 * Handle booting of model.
 *
 * @var string
 */
 public static function boot()
 {
     static::created(function ($data) {
        event(new SendNotificationData($data));
     });

     parent::boot();
 }

这是我的 SendNotificationData 活动:

namespace App\Events;

use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class SendNotificationData extends Event implements ShouldBroadcast
{
    use SerializesModels;

    public $new_notification_data;

    /**
     * Create a new event instance.
     *
     * @param $notification_data
     * @return void
     */
    public function __construct($new_notification_data)
    {
        $this->new_notification_data = $new_notification_data;
    }

    /**
     * Get the channels the event should be broadcast on.
     *
     * @return array
     */
    public function broadcastOn()
    {
        return ['new-notification'];
    }

    /**
     * Customize event name.
     *
     * @return array
     */
    public function broadcastAs()
    {
        return 'private-send-new-notification';
    }
}

Javascript

var newNotificationChannel = pusher.subscribe('new-notification');

newNotificationChannel.bind("private-send-new-notification", function(data) {
        addNotification(data);
}); //This gives me no error in the console and the 404 error still shows up even if i remove this..

function addNotification(data)
{
    console.log(data);
    $('.notification-link').closest('li').append('<a href="#">This is a sample notification!!!</a>');
}

现在,如果我尝试在我的控制器中添加一些随机通知,事件就会触发。但是,它向我显示了 404 错误页面。当我删除 ShouldBroadcast 接口或删除构造函数的内容时,错误不再出现。当我的其他事件运行良好时,我很困惑是什么导致了这样的错误。我可能遗漏了什么,请指导我。

我不敢相信,这是由于模型中的 $incrementing 变量被设置为 false 而不是 true 造成的。如果只有 laravel 会向我显示正确的错误堆栈跟踪。