Laravel雄辩与发现 [英] Laravel Eloquent with and find
本文介绍了Laravel雄辩与发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文章:: with('category') - > find($ ids)
我有一个数组到字符串转换异常。
但是,如果我拆分查询分为两部分:
$ articles = Article :: with('category')
和
$ articles = $文章 - > find($ ids)
我没有得到任何异常,结果是正确的
解决方案
只是为了后代...其他方式你可以这样做:
Article :: with('category') - > whereIn('id',$ ids) - > get();
这应该更好(性能更好),因为它将查询留给数据库管理器
Why is this not working?
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')
and
$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 better (more performant), because it's leaving the query to the database manager
这篇关于Laravel雄辩与发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文