2014-03-27 136 views
1

我明白,做一個選擇查詢laravel:多重選擇查詢

$bearLawly = Bear::where('name', '=', 'Lawly')->first(); 

但如何我做一個選擇查詢,如

SELECT * FROM bear where name = 'abc' AND age => '5' AND title = 'kid' ORDER BY name LIMIT 5, 10 

謝謝!

回答

1

你可以試試這個:

$bearLawly = Bear::where('name', 'abc') // By default = will be used, so optional 
       ->where('age', '>=', '5') 
       ->where('title', 'kid') 
       ->orderBy('name') // or orderBy('name', 'desc') for reverse 
       ->take(5)->skip(10)->get(); 

根據下面的查詢:

SELECT * FROM bear where name = 'abc' AND age => '5' AND title = 'kid' ORDER BY name LIMIT 5, 10 
+0

非常感謝 – dan

+0

@dan,非常歡迎您:-) –

0

只是把它們連:

$bearLawly = Bear::where('name', 'Lawly')->where('age', '5')->first(); 
+0

如果我不想只是第一個發現了什麼,但'ORDER BY name LIMIT 5,10'? – dan