1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bantenprov\VueOpd\Http\Controllers; |
4
|
|
|
|
5
|
|
|
/* Require */ |
6
|
|
|
use App\Http\Controllers\Controller; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Bantenprov\BudgetAbsorption\Facades\VueOpdFacade; |
9
|
|
|
|
10
|
|
|
/* Models */ |
11
|
|
|
use Bantenprov\VueOpd\Models\Bantenprov\VueOpd\VueOpd; |
12
|
|
|
|
13
|
|
|
/* Etc */ |
14
|
|
|
use Validator; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The VueOpdController class. |
18
|
|
|
* |
19
|
|
|
* @package Bantenprov\VueOpd |
20
|
|
|
* @author bantenprov <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class VueOpdController extends Controller |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Create a new controller instance. |
26
|
|
|
* |
27
|
|
|
* @return void |
|
|
|
|
28
|
|
|
*/ |
29
|
|
|
public function __construct(VueOpd $vue_opd) |
30
|
|
|
{ |
31
|
|
|
$this->vue_opd = $vue_opd; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Display a listing of the resource. |
36
|
|
|
* |
37
|
|
|
* @return \Illuminate\Http\Response |
38
|
|
|
*/ |
39
|
|
|
public function index(Request $request) |
40
|
|
|
{ |
41
|
|
|
if (request()->has('sort')) { |
42
|
|
|
list($sortCol, $sortDir) = explode('|', request()->sort); |
43
|
|
|
|
44
|
|
|
$query = $this->vue_opd->orderBy($sortCol, $sortDir); |
45
|
|
|
} else { |
46
|
|
|
$query = $this->vue_opd->orderBy('id', 'asc'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
if ($request->exists('filter')) { |
50
|
|
|
$query->where(function($q) use($request) { |
51
|
|
|
$value = "%{$request->filter}%"; |
52
|
|
|
$q->where('id', 'like', $value) |
53
|
|
|
->orWhere('kunker', 'like', $value) |
54
|
|
|
->orWhere('name', 'like', $value) |
55
|
|
|
->orWhere('kunker_sinjab', 'like', $value) |
56
|
|
|
->orWhere('kunker_simral', 'like', $value) |
57
|
|
|
->orWhere('levelunker', 'like', $value) |
58
|
|
|
->orWhere('njab', 'like', $value) |
59
|
|
|
->orWhere('npej', 'like', $value); |
60
|
|
|
}); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$perPage = request()->has('per_page') ? (int) request()->per_page : null; |
64
|
|
|
$response = $query->paginate($perPage); |
65
|
|
|
|
66
|
|
|
return response()->json($response) |
67
|
|
|
->header('Access-Control-Allow-Origin', '*') |
68
|
|
|
->header('Access-Control-Allow-Methods', 'GET'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Show the form for creating a new resource. |
73
|
|
|
* |
74
|
|
|
* @return \Illuminate\Http\Response |
75
|
|
|
*/ |
76
|
|
|
public function create() |
77
|
|
|
{ |
78
|
|
|
// |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Display the specified resource. |
83
|
|
|
* |
84
|
|
|
* @param \App\VueOpd $vue_opd |
|
|
|
|
85
|
|
|
* @return \Illuminate\Http\Response |
86
|
|
|
*/ |
87
|
|
|
public function store(Request $request) |
88
|
|
|
{ |
89
|
|
|
// |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Store a newly created resource in storage. |
94
|
|
|
* |
95
|
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
96
|
|
|
* @return \Illuminate\Http\Response |
97
|
|
|
*/ |
98
|
|
|
public function show($id) |
99
|
|
|
{ |
100
|
|
|
// |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Show the form for editing the specified resource. |
105
|
|
|
* |
106
|
|
|
* @param \App\VueOpd $vue_opd |
|
|
|
|
107
|
|
|
* @return \Illuminate\Http\Response |
108
|
|
|
*/ |
109
|
|
|
public function edit($id) |
110
|
|
|
{ |
111
|
|
|
// |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Update the specified resource in storage. |
116
|
|
|
* |
117
|
|
|
* @param \Illuminate\Http\Request $request |
118
|
|
|
* @param \App\VueOpd $vue_opd |
|
|
|
|
119
|
|
|
* @return \Illuminate\Http\Response |
120
|
|
|
*/ |
121
|
|
|
public function update(Request $request, $id) |
122
|
|
|
{ |
123
|
|
|
// |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Remove the specified resource from storage. |
128
|
|
|
* |
129
|
|
|
* @param \App\VueOpd $vue_opd |
|
|
|
|
130
|
|
|
* @return \Illuminate\Http\Response |
131
|
|
|
*/ |
132
|
|
|
public function destroy($id) |
133
|
|
|
{ |
134
|
|
|
$vue_opd = $this->vue_opd->findOrFail($id); |
135
|
|
|
|
136
|
|
|
if ($vue_opd->delete()) { |
137
|
|
|
$response['status'] = true; |
|
|
|
|
138
|
|
|
} else { |
139
|
|
|
$response['status'] = false; |
|
|
|
|
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return json_encode($response); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.