【问题标题】:Method Illuminate\Database\Eloquent\Collection::with does not exist [closed]方法 Illuminate\Database\Eloquent\Collection::with 不存在 [关闭]
【发布时间】:2022-01-10 23:24:59
【问题描述】:

有什么解决办法? 提前致谢!

【问题讨论】:

  • Please don't post screenshots of text。它们无法被屏幕阅读器等自适应技术的用户搜索或复制,甚至无法使用。相反,将代码作为文本直接粘贴到您的问题中。如果选择它并单击{} 按钮或Ctrl+K,则代码块将缩进四个空格,这将导致其呈现为代码。

标签: laravel eloquent collections model controller


【解决方案1】:

Here is the reference

请参考给定的链接。参数应该与给定链接的示例类似。

【讨论】:

  • 这应该是您问题的答案还是一部分?在第一种情况下,请阅读How to Answer 然后澄清。在后者中,请删除它并改为编辑您的问题。
【解决方案2】:

这一行:

$fileValue= T_S_Ticket::where("tstID","=",$id)->get();

返回一个集合,所以当你在下一行使用'with'时你会得到这个错误。 要修复它,只需加载关系并在同一行中获取唯一的结果:

$fileValue= T_S_Ticket::with('fields')->find($id);

【讨论】:

  • ` $fileValue = T_S_Ticket::with('files')->where("tstID", "=", $id)->get(); ` 我试过这个,但现在找不到列的错误.. Illuminate\Database\QueryException SQLSTATE[42S22]: Column not found: 1054 Unknown column 'messages.file_id' in 'field list' (SQL: select files.*, messages.file_id` as laravel_through_key from files inner join messages on messages.id = files.msgID 其中messages.file_id in (0))`
猜你喜欢
  • 2020-01-25
  • 1970-01-01
  • 2020-11-21
  • 2021-09-08
  • 2020-11-13
  • 2019-12-11
  • 2020-02-04
  • 2019-11-12
  • 2019-05-24
相关资源
最近更新 更多