Laravel Query Builder使用join()查询的结果 [英] Laravel Query Builder result using join() query

查看:559
本文介绍了Laravel Query Builder使用join()查询的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下查询工作正常,但问题在于它在输出结果中提供事件表的ID而不是任务表的ID.

The following query works fine, but the problem is that it gives the id of the events table instead of tasks table id in the output result.

Task::join('events', function ($join) {
    $join->on('events.task_id', '=', 'tasks.id')
        ->where('events.event_type', '=', 'Task')
        ->where('events.task_stage', '!=', 'assigned');
})->select('tasks.*')
->get();

推荐答案

尝试一下,应该可以使用

Try this, one should work

->select('*', 'tasks.id as taskID')->get();

这是因为任务和事件表可能都具有id字段.因此,您需要使用单独的查询来指定ID.

This is because maybe both tasks and events table have id field. So u need to use a separate query to specify the id.

这篇关于Laravel Query Builder使用join()查询的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆