gpt4 book ai didi

php - "Maximum execution time of 60 seconds is exceeded"当我重写 toArray() 函数时

转载 作者:可可西里 更新时间:2023-11-01 00:39:01 24 4
gpt4 key购买 nike

我需要覆盖函数 toArray() 来检查用户是否有适当的权限来获取特定的列,所以我创建了这个函数:

public function toArray( $options = 0 )
{
if(!auth()->user()->hasPermissionTo('users.show.email')) {
$this->hidden[] = 'email';
}

// etc ...

return parent::toJson($options);
}

但是当我在 Controller 中使用 User::Get() 来获取所有用户的列表时,我没有得到任何结果,但是 60 秒后我得到:

[2019-04-06 23:18:33] local.ERROR: Maximum execution time of 60 seconds exceeded {"userId":1,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 1): Maximum execution time of 60 seconds exceeded at C:\\xampp\\htdocs\\starter\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\Arr.php:162)
[stacktrace]

如果我不覆盖 toArray() 函数,一切都很好。

最佳答案

在最后一行,您调用了 parent::toJson() 方法,它在内部 calls $this->jsonSerialize() ,还有这个 calls $this->toArray() — 您的重写函数,因此进入无限调用循环。

在您重写的函数中,您应该改为调用 parent::toArray()

关于php - "Maximum execution time of 60 seconds is exceeded"当我重写 toArray() 函数时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55554373/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com