gpt4 book ai didi

php - 消息为 'Call to undefined method Illuminate\Database\Query\Builder::toArray()' 的 BadMethodCallException

转载 作者:可可西里 更新时间:2023-11-01 12:54:04 31 4
gpt4 key购买 nike

我正在与@Jeffrey_way 系列的 Laracasts 一起工作 Many to Many Relations (With Tags)

下面是我使用 Laravel Tinker 在 CMD 中编写的代码:

执行最后一行代码后($article->tags()->toArray();

虽然我的代码似乎一切正常,但我仍然收到以下错误:

BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::toArray()'

最佳答案

如果您想实际“获取”关系数据,则不要在标签 周围加上括号。这会工作得很好:

$article->tags->toArray();

当您需要“查询”该集合(例如同步、保存、附加)时,您可以在括号中加上括号。

引用:https://laravel.com/docs/5.1/eloquent-relationships#many-to-many

关于php - 消息为 'Call to undefined method Illuminate\Database\Query\Builder::toArray()' 的 BadMethodCallException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37804478/

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