rully
5 months ago
339
1
Laravel

group latest sales results by salescode

Posted 5 months ago by rully

$hari = DB::table('users')->where('result_type','=','closing')->join('results','users.id','=','results.user_id') ->select(DB::raw('results.salescode,latitude,longitude')) ->groupBy('salescode','latitude','longitude') ->orderBy('results.created_at','desc') ->get();

in this code i wanna grouping sales result by salescode,latitude,long. but when i grouping salescode sales results, there is a double salescode and does not take the final sales result (latest results/salescode,long,latt)

note: only each salescode and the latest results

and this is the ouput

{ "status": 200, "data": [ { "salescode": "A003", "latitude": "999234", "longitude": "-32" }, { "salescode": "A002", "latitude": "999234", "longitude": "-32" }, { "salescode": "A001", "latitude": "999234", "longitude": "-67723123" }, { "salescode": "A001", "latitude": "s", "longitude": "s" }, { "salescode": "A001", "latitude": null, "longitude": null } ] }

Please sign in or create an account to participate in this conversation.