Problem plunk laravel 5.5

1

I tried to count an array by plunk (), by means of a foreach, but for some reason it always remains in the first element and does not tell me the rest, should I use each ()?

* @return \Illuminate\Http\Response
     */
    public function reportes(Request $request)
    { 
        $request->user()->authorizeRoles(['admin']);

        $reporuser=usuarios::pluck('usuario_ad', 'user_id')->unique();

          foreach($reporuser as $reporuse)

          {

            $conteo=usuarios::where('usuario_ad',$reporuse);
            return  view('usuario.reportes',compact('conteo'));

          }

        
    }

UPDATE

I want it to count all the users that a user has entered

Rather, I just want to do a foreach to tell me everything in this,

 $reporuser=usuarios::pluck('usuario_ad', 'user_id')->unique();

but with the foreach I do, only one element comes out and the others do not.

    
asked by zereft 14.12.2018 в 02:23
source

1 answer

1

I would think that the simplest solution is to group and count, this is a typical case:

usuarios::select('usuario_ad as usuario', DB::raw('count(*) as conteo'))
          ->groupBy('usuario_ad')
          ->get()
          ->pluck('conteo', 'usuario');

From then on it is to play with the pluck delivery fix

    
answered by 14.12.2018 / 02:40
source