user
我为保存实例时设置了一个观察者。但是,传递给观察者方法的模型实例包含数据库插入之前的数据。该事件是通过 Lighthouse 运行 GraphQL 突变来触发的。如果我手动设置用户组并保存它,观察者会按预期执行。
这是一个设置用户组的示例:
mutation {
updateUser(input: {
id: 1
groups: {
sync: [1]
}
}) {
groups { id }
}
}
目前我的UserObserver::saved
样子:
public function saved(User $user)
{
// Shows the groups prior to the update
dump($user->groups->toArray());
// Even a raw query doesn't get the updated groups
dump(DB::select('select * from group_user where userId=1'));
}
这是使用 Laravel 5.8.35 和 Lighthouse 4.6