Code Duplication    Length = 155-155 lines in 8 locations

src/Http/Controllers/BrandController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\Brand;
6
use Illuminate\Http\Request;
7
8
class BrandController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $brands = Brand::paginate(5);
23
24
        return view('manteniments/brand/index', ['brands' => $brands]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/brand/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        Brand::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/brand');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $brand = Brand::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($brand == null || count($brand) == 0) {
82
          return redirect()->intended('/mnt/brand');
83
      }
84
85
        return view('manteniments/brand/edit', ['brand' => $brand]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $brand = Brand::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        Brand::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/brand');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        Brand::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/brand');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $brands = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/brand/index', ['brands' => $brands, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = brand::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163

src/Http/Controllers/LocationController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\Location;
6
use Illuminate\Http\Request;
7
8
class LocationController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $locations = Location::paginate(5);
23
24
        return view('manteniments/location/index', ['locations' => $locations]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/location/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        Location::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/location');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $location = Location::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($location == null || count($location) == 0) {
82
          return redirect()->intended('/mnt/location');
83
      }
84
85
        return view('manteniments/location/edit', ['location' => $location]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $location = Location::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        Location::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/location');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        Location::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/location');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $locations = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/location/index', ['locations' => $locations, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = location::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163

src/Http/Controllers/MoneySourceController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\MoneySource;
6
use Illuminate\Http\Request;
7
8
class MoneySourceController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $moneySources = MoneySource::paginate(5);
23
24
        return view('manteniments/moneySource/index', ['moneySources' => $moneySources]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/moneySource/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        MoneySource::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/moneySource');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $moneySource = MoneySource::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($moneySource == null || count($moneySource) == 0) {
82
          return redirect()->intended('/mnt/moneySource');
83
      }
84
85
        return view('manteniments/moneySource/edit', ['moneySource' => $moneySource]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $moneySource = MoneySource::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        MoneySource::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/moneySource');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        MoneySource::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/moneySource');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $moneySources = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/moneySource/index', ['moneySources' => $moneySources, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = MoneySource::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163

src/Http/Controllers/ProviderController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\Provider;
6
use Illuminate\Http\Request;
7
8
class ProviderController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $providers = Provider::paginate(5);
23
24
        return view('manteniments/providers/index', ['providers' => $providers]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/providers/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        Provider::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/provider');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $provider = Provider::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($provider == null || count($provider) == 0) {
82
          return redirect()->intended('/mnt/provider');
83
      }
84
85
        return view('manteniments/providers/edit', ['provider' => $provider]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $provider = Provider::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        Provider::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/provider');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        Provider::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/provider');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $providers = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/providers/index', ['providers' => $providers, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = provider::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163

src/Models/BrandController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\Brand;
6
use Illuminate\Http\Request;
7
8
class BrandController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $brands = Brand::paginate(5);
23
24
        return view('manteniments/brand/index', ['brands' => $brands]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/brand/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        Brand::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/brand');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $brand = Brand::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($brand == null || count($brand) == 0) {
82
          return redirect()->intended('/mnt/brand');
83
      }
84
85
        return view('manteniments/brand/edit', ['brand' => $brand]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $brand = Brand::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        Brand::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/brand');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        Brand::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/brand');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $brands = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/brand/index', ['brands' => $brands, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = brand::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163

src/Models/LocationController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\Location;
6
use Illuminate\Http\Request;
7
8
class LocationController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $locations = Location::paginate(5);
23
24
        return view('manteniments/location/index', ['locations' => $locations]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/location/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        Location::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/location');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $location = Location::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($location == null || count($location) == 0) {
82
          return redirect()->intended('/mnt/location');
83
      }
84
85
        return view('manteniments/location/edit', ['location' => $location]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $location = Location::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        Location::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/location');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        Location::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/location');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $locations = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/location/index', ['locations' => $locations, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = location::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163

src/Models/MoneySourceController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\MoneySource;
6
use Illuminate\Http\Request;
7
8
class MoneySourceController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $moneySources = MoneySource::paginate(5);
23
24
        return view('manteniments/moneySource/index', ['moneySources' => $moneySources]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/moneySource/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        MoneySource::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/moneySource');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $moneySource = MoneySource::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($moneySource == null || count($moneySource) == 0) {
82
          return redirect()->intended('/mnt/moneySource');
83
      }
84
85
        return view('manteniments/moneySource/edit', ['moneySource' => $moneySource]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $moneySource = MoneySource::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        MoneySource::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/moneySource');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        MoneySource::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/moneySource');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $moneySources = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/moneySource/index', ['moneySources' => $moneySources, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = MoneySource::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163

src/Models/ProviderController.php 1 location

@@ 8-162 (lines=155) @@
5
use App\Provider;
6
use Illuminate\Http\Request;
7
8
class ProviderController extends Controller
9
{
10
    /**
11
      * Display a listing of the resource.
12
      *
13
      * @return \Illuminate\Http\Response
14
      */
15
     public function __construct()
16
     {
17
         $this->middleware('auth');
18
     }
19
20
    public function index()
21
    {
22
        $providers = Provider::paginate(5);
23
24
        return view('manteniments/providers/index', ['providers' => $providers]);
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('manteniments/providers/create');
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validateInput($request);
47
        Provider::create([
48
         'name'          => $request['name'],
49
         'shortName'     => $request['shortName'],
50
         'description'   => $request['description'],
51
         'date_entrance' => $request['date_entrance'],
52
         'last_update'   => $request['last_update'],
53
           ]);
54
55
        return redirect()->intended('mnt/provider');
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param int $id
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function show($id)
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function edit($id)
78
    {
79
        $provider = Provider::find($id);
80
      // Redirect to country list if updating country wasn't existed
81
      if ($provider == null || count($provider) == 0) {
82
          return redirect()->intended('/mnt/provider');
83
      }
84
85
        return view('manteniments/providers/edit', ['provider' => $provider]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return \Illuminate\Http\Response
95
     */
96
    public function update(Request $request, $id)
97
    {
98
        $provider = Provider::findOrFail($id);
99
        $input = [
100
        'name'          => $request['name'],
101
        'shortName'     => $request['shortName'],
102
        'description'   => $request['description'],
103
        'date_entrance' => $request['date_entrance'],
104
        'last_update'   => $request['last_update'],
105
      ];
106
        $this->validate($request, [
107
      'name' => 'required|max:60',
108
      ]);
109
        Provider::where('id', $id)
110
          ->update($input);
111
112
        return redirect()->intended('mnt/provider');
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param int $id
119
     *
120
     * @return \Illuminate\Http\Response
121
     */
122
    public function destroy($id)
123
    {
124
        Provider::where('id', $id)->delete();
125
126
        return redirect()->intended('mnt/provider');
127
    }
128
129
    public function search(Request $request)
130
    {
131
        $constraints = [
132
            'name'      => $request['name'],
133
            'shortName' => $request['shortName'],
134
            ];
135
        $providers = $this->doSearchingQuery($constraints);
136
137
        return view('manteniments/providers/index', ['providers' => $providers, 'searchingVals' => $constraints]);
138
    }
139
140
    private function doSearchingQuery($constraints)
141
    {
142
        $query = provider::query();
143
        $fields = array_keys($constraints);
144
        $index = 0;
145
        foreach ($constraints as $constraint) {
146
            if ($constraint != null) {
147
                $query = $query->where($fields[$index], 'like', '%'.$constraint.'%');
148
            }
149
            $index++;
150
        }
151
152
        return $query->paginate(5);
153
    }
154
155
    private function validateInput($request)
156
    {
157
        $this->validate($request, [
158
        'name'      => 'required|max:60|unique:provider',
159
        'shortName' => 'required|max:6|unique:provider',
160
    ]);
161
    }
162
}
163