Code Duplication    Length = 46-50 lines in 2 locations

src/Http/Controllers/StateController.php 1 location

@@ 37-82 (lines=46) @@
34
         * 
35
         * @return json
36
         */
37
        public function index(Request $request)
38
        {
39
            //dd(response()->json(['message' => 'success', 'status' => true]));
40
            // $response;
41
42
            // $param = explode('|',$req->get('sort'));
43
44
            // if($req->get('filter') != ''){
45
            //     $search = "%{$req->get('filter')}%";
46
            //     $response = $this->stateModel->where('name','like',$search)->orderBy($param[0], $param[1])->paginate(10);
47
            // }else{
48
            //     if($req->get('sort') == ''){
49
            //         $response = $this->stateModel->paginate(10);
50
            //     }else{
51
            //         $response = $this->stateModel->orderBy($param[0], $param[1])->paginate(10);     
52
            //     }                
53
            // }
54
55
            if (request()->has('sort')) {
56
                list($sortCol, $sortDir) = explode('|', request()->sort);
57
    
58
                $query = $this->stateModel->orderBy($sortCol, $sortDir);
59
            } else {
60
                $query = $this->stateModel->orderBy('id', 'asc');
61
            }
62
    
63
            if ($request->exists('filter')) {
64
                $query->where(function($q) use($request) {
65
                    $value = "%{$request->filter}%";
66
                    $q->where('label', 'like', $value)
67
                        ->orWhere('description', 'like', $value);
68
                });
69
            }
70
    
71
            $perPage = request()->has('per_page') ? (int) request()->per_page : null;
72
            $response = $query->paginate($perPage);
73
            
74
            foreach($response as $workflow){            
75
                array_set($response->data, 'workflow_id', $workflow->workflow->label);           
76
            }
77
78
            
79
80
            return response()->json($response);
81
            
82
        }
83
84
        /**
85
         * [Function] create

src/Http/Controllers/TransitionController.php 1 location

@@ 38-87 (lines=50) @@
35
     * 
36
     * @return json
37
     */
38
    public function index(Request $request)
39
    {
40
        // $response;
41
42
        //     $param = explode('|',$req->get('sort'));
43
44
        //     if($req->get('filter') != ''){
45
        //         $search = "%{$req->get('filter')}%";
46
        //         $response = $this->transitionModel->where('name','like',$search)->orderBy($param[0], $param[1])->paginate(10);
47
        //     }else{
48
        //         if($req->get('sort') == ''){
49
        //             $response = $this->transitionModel->paginate(10);
50
        //         }else{
51
        //             $response = $this->transitionModel->orderBy($param[0], $param[1])->paginate(10);     
52
        //         }                
53
        //     }
54
55
        //     foreach($response as $kegiatan){            
56
        //         array_set($response->data, 'workflow_id', $kegiatan->kegiatan->label);           
57
        //     }
58
59
            // ===================================================
60
61
        if (request()->has('sort')) {
62
            list($sortCol, $sortDir) = explode('|', request()->sort);
63
64
            $query = $this->transitionModel->orderBy($sortCol, $sortDir);
65
        } else {
66
            $query = $this->transitionModel->orderBy('id', 'asc');
67
        }
68
69
        if ($request->exists('filter')) {
70
            $query->where(function($q) use($request) {
71
                $value = "%{$request->filter}%";
72
                $q->where('label', 'like', $value)
73
                    ->orWhere('description', 'like', $value);
74
            });
75
        }
76
77
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
78
        $response = $query->paginate($perPage);
79
        
80
        foreach($response as $workflow){            
81
            array_set($response->data, 'workflow_id', $workflow->getWorkflow->label);           
82
        }
83
84
        
85
86
        return response()->json($response);
87
    }
88
89
    /**
90
     * [Function] create