2016-07-10 67 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 Query Builder取多表

回答

0

你可以嘗試這樣的:

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

其工作,,感謝ü這麼多。 –

相關問題