内联Laravel 5.2 [英] Inner Join laravel 5.2

查看:167
本文介绍了内联Laravel 5.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

资深编码员,

我正在尝试使用内部联接查询从我的相对表中获取多个数据..我正在尝试做的是将(project_id作为company_name-subproject_id作为subproject_title ).我试图使用查询,因为我将在下面声明.另外,我还将发布表格的打印屏幕.

I'm trying to use an inner join query to get multiple data from my relative tables.. What i'm trying to do is to get the (project_id as company_name - subproject_id as subproject_title). I tried to use the query as I will state below. Also I will post printscreens of my tables.

$values = DB::table('hour_registrations')->join('projects', 'id', '=', 'id')->join('subprojects','id', '=', 'id')->select('projects.*', 'id', 'subprojects.id')->get();

我很想帮助我解决我的问题,因为我现在不知道该怎么办.

I would love some help with my question as I do not understand what to do now..

推荐答案

我认为这应该可以解决问题(如果我正确理解了您的表结构).

I think this should do the trick (if I understood your table structure correctly).

我鼓励您阅读 Joins 上的Laravel官方文档.. >

I would encourage you to read the official Laravel documentation on Joins.

$query = DB::table('projects')
           ->join('subprojects', 'projects.id', '=', 'subprojects.project_id')
           ->join('companies', 'projects.company_id', '=', 'companies.id')
           ->select('companies.company_name', 'projects.id', 'subprojects.id', 'subprojects.title')
           ->get();

这篇关于内联Laravel 5.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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