2015-11-12 29 views
0

我有很多困難找出如何使用此集合來計數行。雄辯laravel:如何從一個 - >獲得行計數()

$wordlist = \DB::table('wordlist')->where('id', '<=', $correctedComparisons) 
       ->get(); 

我試過adding->count()但沒有奏效。我曾嘗試過count($wordlist)。我不確定如果不需要第二個請求作爲a->count()方法,該怎麼辦。

回答

8

count是一種收集方法。查詢生成器返回一個數組。因此,爲了得到計數,你只指望它就像你通常會用一個數組:

$wordCount = count($wordlist); 

如果你有一個詞表模式,那麼你可以用雄辯得到一個集合,然後用收集的count方法。例如:

$wordlist = Wordlist::where('id', '<=', $correctedComparisons)->get(); 
$wordCount = $wordlist->count(); 

有/是在具有查詢生成器返回的集合在這裏討論:https://github.com/laravel/framework/issues/10478

然而截至目前,查詢生成器都返回數組。