[FIXED] count where they don't have the same ID

Issue

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');

enter image description here

Solution

$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'));

Answered By – Andrew Godby

Answer Checked By – Pedro (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published