2017-10-21 37 views
0
User table 

id | name | user_type | email   | password 
1 | John | 1   | [email protected] | something 
2 | Roy | 1   | [email protected] | something 
3 | Rax | 1   | [email protected] | something 
4 | Ren | 1   | [email protected] | something 

AssignUser Table 

id | user_id  | assign_to_math | assign_to_chemistry 
1 | 3   | 2    | 1 
2 | 4   | 1    | 2 

所以,這裏是用戶表,其中四個用戶都無濟於事 現在,在分配表中第一行RAX是分配tuitoin的數學羅伊和化學約翰laravel 5的關係有一個

我想要得到的與關係約翰和羅伊的細節

我的用戶模型試圖

public function getInfoFormathTutor(){ 
     return $this->hasOne('App\AssignUser', 'id', 'assign_to_math'); 
    } 

它返回我空值,不知道爲什麼,請幫助 在此先感謝

+0

你是什麼'應用程序\ AssignUser'模型是什麼樣子? – am05mhz

回答

0

嘗試:

public function getInfoFormathTutor(){ 
    return $this->hasOne('App\AssignUser', 'assign_to_math', 'id'); 
}