[英]Join 4 tables that have same id laravel
I have 4 table : user
, education
, family
, work
我有4个表: user
, education
, family
, work
Table user : 表用户:
id_user | name | address |province|tlp|
---------------------------------------
1 |andi | xxx | xxy |123|
table education : 表教育:
id_education | id_user | year |school |
---------------------------------------
1 | 1 | 1990 | aaa |
2 | 1 | 1994 | bbb |
table family : 表族:
id_family | id_user | name |status |
---------------------------------------
1 | 1 | ddd | wife |
2 | 1 | eee | first children |
3 | 1 | fff | second children |
table work : 表工作:
id_work | id_user | year |place |
---------------------------------------
1 | 1 | 2004 | ggg |
2 | 1 | 2010 | hhh |
I wanna get all of the data in the tables that has sama id_user
我想获得具有sama id_user
的表中的所有数据
public function show($id) {
$user = DB::table('user')
-> join('education', 'user.id_user', '=', 'education.id_user')
-> join('family', 'user.id_user', '=', 'family.id_user')
-> join('work', 'user.id_user', '=', 'work.id_user')
->where('id_user', '=', $id)
->first();
return View::make('user.show')->with('user', $user)->with('title', 'Show User');
}
but it gives me error : 但它给了我错误:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_user' in where clause is ambiguous
please kindly help me, thank you :) 请帮助我,谢谢:)
试试.. ->where('user.id_user', '=', $id) ..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.