2016-07-10 2 views
0
$name = $_POST['name']; 
$statement = $db->prepare("SELECT * FROM authors WHERE name = ?"); 
$statement->execute(array($name)); 
$author_id = $statement->fetch()["id"]; 

$statement = $db->prepare("SELECT * FROM quotes WHERE author_id = ?"); 
$statement->execute(array($author_id)); 
$result = $statement->fetchAll(PDO::FETCH_ASSOC); 
foreach ($result as $row) { 
$quote = $row['quote']; 
    } 

어떻게 laravel 쿼리 작성기에서 동일한 작업을 수행 할 수 있습니까?Laravel 쿼리 빌더 다중 테이블 가져 오기

답변

0

이 같은 시도 할 수 있습니다 :

$name = $_POST['name']; 
$where[] = ['authors.name ', $name]; 
$data = \DB::table('authors') 
    ->join('quotes', 'quotes.author_id', '=', 'authors.id') 
    ->where($where) 
    ->get(); 
+0

의 작업은 ,, 너무 많이 U 감사합니다. –