加入4个具有相同id laravel的表

时间:2015-02-19 20:47:08

标签: php mysql laravel

我有4个表:usereducationfamilywork

表用户:

id_user | name | address |province|tlp|
---------------------------------------
1       |andi  | xxx     | xxy    |123|
表教育:

id_education | id_user | year |school |
---------------------------------------
1            |   1     | 1990 | aaa   |
2            |   1     | 1994 | bbb   |

表系列:

id_family  | id_user | name   |status |
---------------------------------------
1          |   1     | ddd    | wife   |
2          |   1     | eee    | first children   |
3          |   1     | fff    | second children  |

表工作:

id_work | id_user | year |place |
---------------------------------------
1       |   1     | 2004 | ggg   |
2       |   1     | 2010 | hhh   |

我想获得具有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');
}

但它给了我错误:

SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id_user' in where clause is ambiguous
请帮助我, 谢谢你:))

1 个答案:

答案 0 :(得分:0)

尝试.. ->where('user.id_user', '=', $id) ..