What is pluck in MySQL select query

Without pluck

 $data['category'] = DB::table('table_name')->select('category', DB::raw('count(*) as total'))->groupBy('category')->where('date','>=',$start_date)->where('date','<=',$end_date)->get();

   "category": [
            {
                "category": "Car",
                "total": 2
            },
            {
                "category": "vehicle",
                "total": 1
            }
        ],

With pluck

 $data['category'] = DB::table('table_name')->select('category', DB::raw('count(*) as total'))->groupBy('category')->where('date','>=',$start_date)->where('date','<=',$end_date)->pluck('total','category')->all();
 "category": {
            "Car": 2,
            "vehicle": 1
        }

Leave a Reply