Code Duplication    Length = 20-25 lines in 5 locations

app/Http/Controllers/Admin/AdvertController.php 1 location

@@ 61-85 (lines=25) @@
58
     * @param object $object
59
     * @param Request $request
60
     */
61
    public function associateRelationships($object, Request $request) {
62
63
        /**
64
         * Validate image ID, if failed set to default
65
         */
66
        $validator = Validator::make($request->all(), [
67
                    'image_id' => 'integer|min:1|exists:image,id',
68
        ]);
69
        
70
        /**
71
         * Validator fails - nothing to do
72
         */
73
        if ($validator->fails()) {
74
75
            
76
        }
77
        
78
        /**
79
         * Validator OK - save it
80
         */
81
        else {
82
83
            $object->images()->associate($request->input('image_id'));
84
        }
85
    }
86
    
87
    /**
88
     * Associate relationships to other table, where ID if object must be present

app/Http/Controllers/Admin/ArticleCategoryController.php 1 location

@@ 56-80 (lines=25) @@
53
     * @param object $object
54
     * @param Request $request
55
     */
56
    public function associateRelationships($object, Request $request) {
57
58
        /**
59
         * Validate image ID, if failed set to default
60
         */
61
        $validator = Validator::make($request->all(), [
62
                    'image_id' => 'required|integer|min:1|exists:image,id',
63
        ]);
64
65
        /**
66
         * Validator fails - nothing to do
67
         */
68
        if ($validator->fails()) {
69
70
            // nothing to do
71
        } 
72
        
73
        /**
74
         * Validator OK - save it
75
         */
76
        else {
77
78
            $object->images()->associate($request->input('image_id'));
79
        }
80
    }
81
82
}
83

app/Http/Controllers/Admin/FeedbackController.php 1 location

@@ 53-76 (lines=24) @@
50
     * @param object $object
51
     * @param Request $request
52
     */
53
    public function associateRelationships($object, Request $request){
54
        
55
        /**
56
         * Validate image ID, if failed set to default
57
         */
58
        $validator = Validator::make($request->all(), [
59
            'image_id' => 'required|integer|min:1|exists:image,id',
60
        ]);
61
62
        /**
63
         * Validator fails - nothing to do
64
         */
65
        if ($validator->fails()) {
66
67
        }
68
        
69
        /**
70
         * Validator OK - save it
71
         */
72
        else{
73
74
            $object->images()->associate($request->input('image_id'));
75
        }   
76
    }  
77
}
78

app/Http/Controllers/Admin/ImageSelectController.php 1 location

@@ 103-122 (lines=20) @@
100
    /**
101
     * Associate relationships to other table
102
     */
103
    public function associateRelationships($object, Request $request){
104
        
105
        /**
106
         * Validate category ID, if failed set to default
107
         */
108
        $validator = Validator::make($request->all(), [
109
            'imagecategory_id' => 'required|integer|min:1|exists:imagecategory,id',
110
        ]);
111
112
        if ($validator->fails()) {
113
114
            $object->imagecategories()->associate(1);
115
        }
116
        else{
117
118
            $object->imagecategories()->associate($request->input('imagecategory_id'));
119
120
        }
121
        
122
    }
123
}
124

app/Http/Controllers/Admin/ImageController.php 1 location

@@ 66-90 (lines=25) @@
63
     * @param object $object
64
     * @param Request $request
65
     */
66
    public function associateRelationships($object, Request $request){
67
        
68
        /**
69
         * Validate category ID, if failed set to default
70
         */
71
        $validator = Validator::make($request->all(), [
72
            'imagecategory_id' => 'required|integer|min:1|exists:imagecategory,id',
73
        ]);
74
        
75
        /**
76
         * Validator fails - set category to default
77
         */
78
        if ($validator->fails()) {
79
80
            $object->imagecategories()->associate(1);
81
        }
82
        
83
        /**
84
         * Validator OK - save it
85
         */
86
        else{
87
88
            $object->imagecategories()->associate($request->input('imagecategory_id'));
89
        } 
90
    }
91
92
    /**
93
     * Save media to storage