json(array('status' => 400, 'errors'=> $e->getMessage() )); } } public function data($type,Request $request) { try{ if ($type == "all") { $data = Pratice_Leaderborad::select(DB::raw(' RANK() OVER (ORDER BY total_score DESC) as rank'),'user_id','category_id',DB::raw('SUM(score) As total_score')) ->groupBy('user_id') ->with('users') ->with('category') ->orderBy('rank','ASC') ->get(); return DataTables()::of($data) ->addIndexColumn() ->make(true); } elseif($type == "today"){ $data = Pratice_Leaderborad::select(DB::raw(' RANK() OVER (ORDER BY total_score DESC) as rank'),'user_id','category_id',DB::raw('SUM(score) As total_score')) ->where('date', date("Y-m-d")) ->groupBy('user_id') ->with('category') ->with('users') ->orderBy('rank','ASC') ->get(); return DataTables()::of($data) ->addIndexColumn() ->make(true); } elseif($type == "month"){ $data = Pratice_Leaderborad::select(DB::raw(' RANK() OVER (ORDER BY total_score DESC) as rank'),'user_id','category_id',DB::raw('SUM(score) As total_score')) ->whereMonth('date', date('m')) ->groupBy('user_id') ->with('category') ->with('users') ->orderBy('rank','ASC') ->get(); return DataTables()::of($data) ->addIndexColumn() ->make(true); } else { $data = Pratice_Leaderborad::select(DB::raw(' RANK() OVER (ORDER BY total_score DESC) as rank'),'user_id','category_id',DB::raw('SUM(score) As total_score')) ->groupBy('user_id') ->with('category') ->with('users') ->orderBy('rank','ASC') ->get(); return DataTables()::of($data) ->addIndexColumn() ->make(true); } } catch (Exception $e) { return response()->json(array('status' => 400, 'errors'=> $e->getMessage() )); } } } @extends('admin.layouts.master') @section('title',__('Label.Pratice Leaderboard')) @section('content')

@yield('title')

{{__('Label.Image')}} {{__('Label.Name')}} {{__('Label.Score')}} {{__('Label.Rank')}} {{__('Label.Category')}}
@endsection @push('scripts') @endpush