小编ben*_*enJ的帖子

Eloquent - 使用字符串值而不是列标题的join子句

我有一个关于Eloquent中的join子句的问题,以及你是否可以加入字符串值而不是表列.

我有下面的代码查询嵌套集合,通过表'分类法'加入表'目的地'中的父/子记录.

$join关闭中的第二个陈述是引起问题的陈述; Eloquent假设这是一个列,当我真的只想加入时t1.parent_type = 'Destination'- 即,t1.parent_typeshould =一个字符串值,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();
Run Code Online (Sandbox Code Playgroud)

是否有可能强迫Eloquent这样做?我尝试过更换'Destination',DB::raw('Destination')但这也不起作用.

亲切地感谢你.

php mysql laravel eloquent

10
推荐指数
2
解决办法
8126
查看次数

标签 统计

eloquent ×1

laravel ×1

mysql ×1

php ×1