i need to count all records in my table, but in the mp_id column there are repetitions
how to count only once where the content of mp_id is repeated?
so that the count is not wrong, i want the mp_id to count only once and not 3 or 4.
$ingresos = Ingresosmp::All()->count('mp_id');
CodePudding user response:
$ingresos = Ingresosmp::All()->unique('mp_id');
$ingresos = count($ingresos);
Verify results with:
dd($ingresos);
Edit: you can condense this into a single line of code, this is just for readability. You can do this by:
$ingresos = count(Ingresosmp::all()->unique('mp_id'));