2016-10-27 1 views
-1

Laravel 웅변 관계이 SQL 문을 변환이 예를 들어 내 SQL 문
내가 2 개 테이블 <br></p> <pre><code>table1 empid lname fname </code></pre> <p><br></p> <pre><code>table2 empid name department </code></pre> <p>이

Select table1.*, table2.department from table1 inner join table2 on table1.empid = table2.empid 
+0

laravel 문서를 참조하십시오 URL의 매개 변수입니다. 꽤 분명합니다. 어딘가에 갇혀 있다면 질문을 게시하십시오 –

+0

'Eloquent Relations'를 사용하려면 '모델'을 사용하여 액세스해야합니다. 거기에서 시작하십시오, [docs] (https://laravel.com/docs/5.3)는 그렇게 쉽게 설명합니다. –

답변

0

입니다 :

table1 
id 
lname 
fname 

table2 
id 
table1_id 
name 
department 

table2.php 모델

class Table2 extends Model 
{ 
protected $primaryKey = 'id'; 

function withTable1() { 
    return $this->hasOne('App\Table1', 'id', 'table1_id'); 
} 

public function show($id){ 
    Table2::with('withTable1')->where('table1_id', $id)->get(); 
} 

}

$ ID는