lundi 30 septembre 2019

Can we get the total record count and the first record only in the same eloquent query?

Can we get the total record count and the first record only in the same eloquent query?

I know we can get the total records via below eloquent queries:

1. Model::count();

2. Collection Method
   Model::all()->count();

And we can get the first record like this:

Model::first();

I have one solution for the same i.e.

$data = Model::all();

1. $count = count($data);
2. $count = $data->count();

And for the first row/data

1. $firstRecord = $data[0];
2. $firstRecord = $data->first();


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2nRBdnf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire