php – Eloquent – 使用字符串值而不是列标题的join子句
发布时间:2020-12-13 13:50:41 所属栏目:PHP教程 来源:网络整理
导读:我有一个关于Eloquent中的join子句的问题,以及你是否可以加入字符串值而不是表列. 我有下面的代码查询嵌套集合,通过表’分类法’加入表’目的地’中的父/子记录. 闭包中的第二个$join语句是导致问题的一个; Eloquent假设这是一个列,当我实际上只想加入t1.par
我有一个关于Eloquent中的join子句的问题,以及你是否可以加入字符串值而不是表列.
我有下面的代码查询嵌套集合,通过表’分类法’加入表’目的地’中的父/子记录. 闭包中的第二个$join语句是导致问题的一个; Eloquent假设这是一个列,当我实际上只想加入t1.parent_type =’Destination’时 – 即,t1.parent_type should =一个字符串值,Destination. $result = DB::connection() ->table('destinations AS d1') ->select(array('d1.title AS level1','d2.title AS level2')) ->leftJoin('taxonomy AS t1',function($join) { $join->on('t1.parent_id','=','d1.id'); $join->on('t1.parent_type','Destination'); }) ->leftJoin('destinations AS d2','d2.id','t1.child_id') ->where('d1.slug',$slug) ->get(); 是否有可能强迫Eloquent这样做?我尝试用DB :: raw(‘Destination’)替换’Destination’,但这也不起作用. 亲切地感谢你.
实现同样目标的另一个最佳方法是:
$result = DB::connection() ->table('destinations AS d1') ->select(array('d1.title AS level1','d1.id'); $join->where('t1.parent_type',$slug) ->get(); 替换你的地方 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |