在laravel 5.4中使用序列化时事件失败

在laravel 5.4中使用序列化时事件失败,laravel,laravel-5.4,Laravel,Laravel 5.4,我有不同的模型,它们描述数据库中的不同表 我在这些课程中使用这种特性 trait ApplicationModelTrait { protected static $_currentModel = null; protected $currentModel; public static function setCurrentModel(ApplicationModel $model) { static::$_currentModel = $m

我有不同的模型,它们描述数据库中的不同表

我在这些课程中使用这种特性

trait ApplicationModelTrait
 {
     protected static $_currentModel = null;

     protected $currentModel;

     public static function setCurrentModel(ApplicationModel $model) {
         static::$_currentModel = $model;
     }   

     public function __construct(array $attributes = [], ApplicationModel $model = null) {
         parent::__construct($attributes);

         $this->currentModel = $model !== null ? $model : static::$_currentModel;

         if($this->currentModel === null) throw new \InvalidArgumentException('No model passed');
     }   
 }
所有型号都相似。唯一的区别是每个模型的数据库中都有哪些字段,所以我在单独的配置中描述了这些字段,并且主模型类
ApplicationModel
有一些处理不同表的方法。比如说

public function getInstanceTable() {
     return 'application_model_instances_' . $this->name;
}

public function getCommentsTable() {
    return 'application_model_instance_' . $this->name . '_comments';
}
其中,
application\u model\u instances\u{name}
包含(显然)此模型的实例,
application\u model\u instance\u{name}\u comments
包含此模型实例的注释

除事件外,一切正常

当我向模型实例添加注释时,我将作为当前模型的参数传递

$comment = new ApplicationModelInstanceComment([], $this->currentModel);
$comment->text = $request->input('comment');
// etc.
在评论被保存后,我希望它能通过websocket立即发送到用户浏览器

事件(新建CommentCreated($comment,$this));//<代码>此表示模型实例类

最后,这一事件

但当我添加注释Laravel时,我的代码抛出一个异常(这是我在Google Chrome的网络选项卡中看到的,因为请求是通过ajax完成的:

Whoops, looks like something went wrong.

1/1 InvalidArgumentException in ApplicationModelTrait.php line 20: No model passed

in ApplicationModelTrait.php line 20
at ApplicationModelInstanceComment->__construct() in SerializesAndRestoresModelIdentifiers.php line 45
at CommentCreated->getRestoredPropertyValue(object(ModelIdentifier)) in SerializesModels.php line 41
at CommentCreated->__wakeup()
at unserialize('O:38:"Illuminate\\Broadcasting\\BroadcastEvent":4:{s:5:"event";O:25:"App\\Events\\CommentCreated":3:{s:7:"comment";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:54:"App\\Models\\Application\\ApplicationModelInstanceComment";s:2:"id";i:68;}s:8:"instance";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:47:"App\\Models\\Application\\ApplicationModelInstance";s:2:"id";i:11;}s:6:"socket";N;}s:10:"connection";N;s:5:"queue";N;s:5:"delay";N;}') in CallQueuedHandler.php line 95
at CallQueuedHandler->failed(array('commandName' => 'Illuminate\\Broadcasting\\BroadcastEvent', 'command' => 'O:38:"Illuminate\\Broadcasting\\BroadcastEvent":4:{s:5:"event";O:25:"App\\Events\\CommentCreated":3:{s:7:"comment";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:54:"App\\Models\\Application\\ApplicationModelInstanceComment";s:2:"id";i:68;}s:8:"instance";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:47:"App\\Models\\Application\\ApplicationModelInstance";s:2:"id";i:11;}s:6:"socket";N;}s:10:"connection";N;s:5:"queue";N;s:5:"delay";N;}'), object(InvalidArgumentException)) in Job.php line 158
at Job->failed(object(InvalidArgumentException)) in FailingJob.php line 33
在创建注释时,我已经将模型传递到ApplicationModelInstanceComment,所以这里一切都很好。反序列化存在一些问题,但我不知道如何处理这个问题

Whoops, looks like something went wrong.

1/1 InvalidArgumentException in ApplicationModelTrait.php line 20: No model passed

in ApplicationModelTrait.php line 20
at ApplicationModelInstanceComment->__construct() in SerializesAndRestoresModelIdentifiers.php line 45
at CommentCreated->getRestoredPropertyValue(object(ModelIdentifier)) in SerializesModels.php line 41
at CommentCreated->__wakeup()
at unserialize('O:38:"Illuminate\\Broadcasting\\BroadcastEvent":4:{s:5:"event";O:25:"App\\Events\\CommentCreated":3:{s:7:"comment";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:54:"App\\Models\\Application\\ApplicationModelInstanceComment";s:2:"id";i:68;}s:8:"instance";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:47:"App\\Models\\Application\\ApplicationModelInstance";s:2:"id";i:11;}s:6:"socket";N;}s:10:"connection";N;s:5:"queue";N;s:5:"delay";N;}') in CallQueuedHandler.php line 95
at CallQueuedHandler->failed(array('commandName' => 'Illuminate\\Broadcasting\\BroadcastEvent', 'command' => 'O:38:"Illuminate\\Broadcasting\\BroadcastEvent":4:{s:5:"event";O:25:"App\\Events\\CommentCreated":3:{s:7:"comment";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:54:"App\\Models\\Application\\ApplicationModelInstanceComment";s:2:"id";i:68;}s:8:"instance";O:45:"Illuminate\\Contracts\\Database\\ModelIdentifier":2:{s:5:"class";s:47:"App\\Models\\Application\\ApplicationModelInstance";s:2:"id";i:11;}s:6:"socket";N;}s:10:"connection";N;s:5:"queue";N;s:5:"delay";N;}'), object(InvalidArgumentException)) in Job.php line 158
at Job->failed(object(InvalidArgumentException)) in FailingJob.php line 33