eloquent laravel: How to get a row count from a ->get()

后端 未结 4 1354
花落未央
花落未央 2021-02-02 05:32

I\'m having a lot of trouble figuring out how to use this collection to count rows.

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


        
4条回答
  •  情深已故
    2021-02-02 05:48

    Direct get a count of row

    Using Eloquent

     //Useing Eloquent
     $count = Model::count();    
    
     //example            
     $count1 = Wordlist::count();
    

    Using query builder

     //Using query builder
     $count = \DB::table('table_name')->count();
    
     //example
     $count2 = \DB::table('wordlist')->where('id', '<=', $correctedComparisons)->count();
    

提交回复
热议问题