Laravel Eloquent with 和 find [英] Laravel Eloquent with and find
本文介绍了Laravel Eloquent with 和 find的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这不起作用?
Article::with('category')->find($ids)
我收到一个数组到字符串的转换异常.
I got a Array to String Conversion Exception.
但是如果我将查询分成这样的两部分:
But if i split the query into 2 parts like this:
$articles = Article::with('category')
和
$articles = $articles->find($ids)
我没有得到任何异常,结果是正确的.
I didn't get any exception and the result is right.
推荐答案
仅供后人使用……您还可以通过以下方式实现:
Just for the posterity... other way you can do this is:
Article::with('category')->whereIn('id', $ids)->get();
这应该更快,因为它将查询留给数据库管理器
This should be faster because it's leaving the query to the database manager
这篇关于Laravel Eloquent with 和 find的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文