在Laravel外使用Eloquent如何写两个字段值相等的记录?
本文介绍了在Laravel外使用Eloquent如何写两个字段值相等的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
要实现 select * from table where userid=parentid and age>30 这种查询应该如何写?没有在文档里找到这种用法.
解决方案
方法一
$results = Model::whereRaw('userid=parentid and age>30')->get();
方法二
$results = DB::table('table_name')->whereRaw('userid=parentid and age>30')->get();
这篇关于在Laravel外使用Eloquent如何写两个字段值相等的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文