1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\Refn; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
|
8
|
|
|
class RefnController extends Controller |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Display a listing of the resource. |
12
|
|
|
* |
13
|
|
|
* @return \Illuminate\Http\Response |
14
|
|
|
*/ |
15
|
|
|
public function index(Request $request) |
16
|
|
|
{ |
17
|
|
|
$query = Refn::query(); |
18
|
|
|
|
19
|
|
|
if ($request->has('searchTerm')) { |
20
|
|
|
$columnsToSearch = ['group', 'refn', 'type']; |
21
|
|
|
$search_term = json_decode($request->searchTerm)->searchTerm; |
22
|
|
|
if (! empty($search_term)) { |
23
|
|
|
$searchQuery = '%'.$search_term.'%'; |
24
|
|
|
foreach ($columnsToSearch as $column) { |
25
|
|
|
$query->orWhere($column, 'LIKE', $searchQuery); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
if ($request->has('columnFilters')) { |
31
|
|
|
$filters = get_object_vars(json_decode($request->columnFilters)); |
32
|
|
|
|
33
|
|
|
foreach ($filters as $key => $value) { |
34
|
|
|
if (! empty($value)) { |
35
|
|
|
$query->orWhere($key, 'like', '%'.$value.'%'); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($request->has('sort.0')) { |
41
|
|
|
$sort = json_decode($request->sort[0]); |
42
|
|
|
$query->orderBy($sort->field, $sort->type); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
if ($request->has('perPage')) { |
46
|
|
|
$rows = $query->paginate($request->perPage); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $rows; |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Show the form for creating a new resource. |
54
|
|
|
* |
55
|
|
|
* @return \Illuminate\Http\Response |
56
|
|
|
*/ |
57
|
|
|
public function create() |
58
|
|
|
{ |
59
|
|
|
// |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Store a newly created resource in storage. |
64
|
|
|
* |
65
|
|
|
* @param \Illuminate\Http\Request $request |
66
|
|
|
* @return \Illuminate\Http\Response |
67
|
|
|
*/ |
68
|
|
|
public function store(Request $request) |
69
|
|
|
{ |
70
|
|
|
$request->validate([ |
71
|
|
|
'refn' => 'required', |
72
|
|
|
]); |
73
|
|
|
|
74
|
|
|
return Refn::create([ |
|
|
|
|
75
|
|
|
'group' => $request->group, |
76
|
|
|
'refn' => $request->refn, |
77
|
|
|
'type' => $request->type, |
78
|
|
|
]); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Display the specified resource. |
83
|
|
|
* |
84
|
|
|
* @param int $id |
85
|
|
|
* @return \Illuminate\Http\Response |
86
|
|
|
*/ |
87
|
|
|
public function show($id) |
88
|
|
|
{ |
89
|
|
|
return Refn::find($id); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Show the form for editing the specified resource. |
94
|
|
|
* |
95
|
|
|
* @param int $id |
96
|
|
|
* @return \Illuminate\Http\Response |
97
|
|
|
*/ |
98
|
|
|
public function edit($id) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
// |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Update the specified resource in storage. |
105
|
|
|
* |
106
|
|
|
* @param \Illuminate\Http\Request $request |
107
|
|
|
* @param int $id |
108
|
|
|
* @return \Illuminate\Http\Response |
109
|
|
|
*/ |
110
|
|
|
public function update(Request $request, $id) |
111
|
|
|
{ |
112
|
|
|
$request->validate([ |
113
|
|
|
'refn' => 'required', |
114
|
|
|
]); |
115
|
|
|
|
116
|
|
|
$refn = Refn::find($id); |
117
|
|
|
$refn->group = $request->group; |
118
|
|
|
$refn->refn = $request->refn; |
119
|
|
|
$refn->type = $request->type; |
120
|
|
|
$refn->save(); |
121
|
|
|
|
122
|
|
|
return $refn; |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Remove the specified resource from storage. |
127
|
|
|
* |
128
|
|
|
* @param int $id |
129
|
|
|
* @return \Illuminate\Http\Response |
130
|
|
|
*/ |
131
|
|
|
public function destroy($id) |
132
|
|
|
{ |
133
|
|
|
$refn = Refn::find($id); |
134
|
|
|
if ($refn) { |
135
|
|
|
$refn->delete(); |
136
|
|
|
|
137
|
|
|
return 'true'; |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return 'false'; |
|
|
|
|
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|