mardi 15 octobre 2019

how do I only display each one of the data without repeating with a distinct laravel?

I have a query that takes id_user from several transactions.

I just want to find the id_user in the user table by taking only 1 of each data.

example: in the query there is a user id [1,1,3,4]

i just want to take [1,3,4]

so the name that comes out is only from id_user [1,3,4] not [1,1,3,4]

I have tried using unique and distinct features but instead the data is repeated several times

this my code :

$arrayDiff = [];
        $totalMasing = [];
        $listuser = [];

        if ($totalSubmitted == 1) {
            for ($i = 0; $i < $totalSubmitted; $i++) {
                $item = $subset[$i]['id_okr'];
                $arrayDiff[] = Okr::find($item)->get();
                $totalMasing[] = Interact::where('id_created', '=', $arrayDiff[0][$i]['id_created'])
                    ->where('status', '=', '2')
                    ->where('id_user', '=', $interact)
                    ->count();

                $listuser[] = User::find($arrayDiff[0][$i]['id_created']);
            }
        }else{
            for ($i = 1; $i < $totalSubmitted; $i++) {
                $item = $subset[$i]['id_okr'];
                $arrayDiff[] = Okr::find($item)->get();
                $totalMasing[] = Interact::where('id_created', '=', $arrayDiff[0][$i]['id_created'])
                    ->where('status', '=', '2')
                    ->where('id_user', '=', $interact)
                    ->count();

                $listuser[] = User::find($arrayDiff[0][$i]['id_created']->distinct('id_created'));

            }

this is my JSON Result :

listuser: [
            {},
            {},
            {}
       ]

any advice for my problem ? thanks so much



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire