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