1 | <?php |
||||
2 | |||||
3 | namespace App\Http\Controllers; |
||||
4 | |||||
5 | use App\Models\Subn; |
||||
6 | use Illuminate\Http\Request; |
||||
7 | |||||
8 | class SubnController 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 = Subn::query(); |
||||
18 | |||||
19 | if ($request->has('searchTerm')) { |
||||
20 | $columnsToSearch = ['subm', 'famf', 'temp', 'ance', 'desc', 'rin']; |
||||
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; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||||
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 | 'desc' => 'required', |
||||
72 | ]); |
||||
73 | |||||
74 | return Subn::create([ |
||||
0 ignored issues
–
show
|
|||||
75 | 'subm' => $request->subm, |
||||
76 | 'famf' => $request->famf, |
||||
77 | 'temp' => $request->temp, |
||||
78 | 'ance' => $request->ance, |
||||
79 | 'desc' => $request->desc, |
||||
80 | 'ordi' => $request->ordi, |
||||
81 | 'rin' => $request->rin, |
||||
82 | ]); |
||||
83 | } |
||||
84 | |||||
85 | /** |
||||
86 | * Display the specified resource. |
||||
87 | * |
||||
88 | * @param int $id |
||||
89 | * @return \Illuminate\Http\Response |
||||
90 | */ |
||||
91 | public function show($id) |
||||
92 | { |
||||
93 | return Subn::find($id); |
||||
0 ignored issues
–
show
|
|||||
94 | } |
||||
95 | |||||
96 | /** |
||||
97 | * Show the form for editing the specified resource. |
||||
98 | * |
||||
99 | * @param int $id |
||||
100 | * @return \Illuminate\Http\Response |
||||
101 | */ |
||||
102 | public function edit($id) |
||||
0 ignored issues
–
show
The parameter
$id is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. ![]() |
|||||
103 | { |
||||
104 | // |
||||
105 | } |
||||
106 | |||||
107 | /** |
||||
108 | * Update the specified resource in storage. |
||||
109 | * |
||||
110 | * @param \Illuminate\Http\Request $request |
||||
111 | * @param int $id |
||||
112 | * @return \Illuminate\Http\Response |
||||
113 | */ |
||||
114 | public function update(Request $request, $id) |
||||
115 | { |
||||
116 | $request->validate([ |
||||
117 | 'desc' => 'required', |
||||
118 | |||||
119 | ]); |
||||
120 | |||||
121 | $subn = Subn::find($id); |
||||
122 | $subn->subm = $request->subm; |
||||
123 | $subn->famf = $request->famf; |
||||
124 | $subn->temp = $request->temp; |
||||
125 | $subn->ance = $request->ance; |
||||
126 | $subn->desc = $request->desc; |
||||
127 | $subn->ordi = $request->ordi; |
||||
128 | $subn->rin = $request->rin; |
||||
129 | $subn->save(); |
||||
130 | |||||
131 | return $subn; |
||||
0 ignored issues
–
show
|
|||||
132 | } |
||||
133 | |||||
134 | /** |
||||
135 | * Remove the specified resource from storage. |
||||
136 | * |
||||
137 | * @param int $id |
||||
138 | * @return \Illuminate\Http\Response |
||||
139 | */ |
||||
140 | public function destroy($id) |
||||
141 | { |
||||
142 | $subn = Subn::find($id); |
||||
143 | if ($subn) { |
||||
144 | $subn->delete(); |
||||
145 | |||||
146 | return 'true'; |
||||
0 ignored issues
–
show
|
|||||
147 | } |
||||
148 | |||||
149 | return 'false'; |
||||
0 ignored issues
–
show
|
|||||
150 | } |
||||
151 | } |
||||
152 |