1

In Lithium, after fetching all rows of a given Model like this:

$users = Users::all();

how can I know how many rows were returned? I'm using the MySQL connector.

Thank you!

Tiago Alves
  • 1,301
  • 2
  • 18
  • 30

1 Answers1

7

If you just want the count

$usersCount = Users::count();

If you want the count of your collection

$users = Users::all();
$usersCount = count($users->data())

I think you can also do

$usersCount = $users->count();

I'm aware the above two methods will return the same result.
The second method is in case he calls Model::find() instead of Model::all().

ton.yeung
  • 4,793
  • 6
  • 41
  • 72