我有一个关于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();
替换你的地方
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。