1 | <?php |
||||
2 | |||||
3 | namespace App\Http\Controllers; |
||||
4 | |||||
5 | use App\Models\Publication; |
||||
6 | use App\Models\Source; |
||||
7 | use Illuminate\Http\Request; |
||||
8 | use Illuminate\Support\Facades\DB; |
||||
9 | |||||
10 | class SourceController extends Controller |
||||
11 | { |
||||
12 | /** |
||||
13 | * Display a listing of the resource. |
||||
14 | * |
||||
15 | * @return \Illuminate\Http\Response |
||||
16 | */ |
||||
17 | public function index(Request $request) |
||||
18 | { |
||||
19 | $query = Source::query()->with(['publication', 'repositories', 'author', 'type']); |
||||
20 | |||||
21 | if ($request->has('searchTerm')) { |
||||
22 | $columnsToSearch = ['titl', 'sour', 'auth', 'data', 'text', 'publ', 'abbr', 'name', 'description', 'repository_id', 'author_id', 'publication_id', 'type_id', 'is_active', 'group', 'quay', 'page']; |
||||
23 | $search_term = json_decode($request->searchTerm)->searchTerm; |
||||
24 | if (! empty($search_term)) { |
||||
25 | $searchQuery = '%'.$search_term.'%'; |
||||
26 | foreach ($columnsToSearch as $column) { |
||||
27 | $query->orWhere($column, 'LIKE', $searchQuery); |
||||
28 | } |
||||
29 | } |
||||
30 | } |
||||
31 | |||||
32 | if ($request->has('columnFilters')) { |
||||
33 | $filters = get_object_vars(json_decode($request->columnFilters)); |
||||
34 | $relationship_column = ['repositories.name', 'author.name', 'publication.name', 'type.name']; |
||||
35 | foreach ($filters as $key => $value) { |
||||
36 | if (! in_array($key, $relationship_column)) { |
||||
37 | if (! empty($value)) { |
||||
38 | $query->orWhere($key, 'like', '%'.$value.'%'); |
||||
39 | } |
||||
40 | } |
||||
41 | } |
||||
42 | } |
||||
43 | |||||
44 | if ($request->has('sort.0')) { |
||||
45 | $sort = json_decode($request->sort[0]); |
||||
46 | $query->orderBy($sort->field, $sort->type); |
||||
47 | } |
||||
48 | |||||
49 | if ($request->has('perPage')) { |
||||
50 | $rows = $query->paginate($request->perPage); |
||||
51 | } |
||||
52 | |||||
53 | return $rows; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||||
54 | } |
||||
55 | |||||
56 | /** |
||||
57 | * Show the form for creating a new resource. |
||||
58 | * |
||||
59 | * @return \Illuminate\Http\Response |
||||
60 | */ |
||||
61 | public function create() |
||||
62 | { |
||||
63 | // |
||||
64 | } |
||||
65 | |||||
66 | /** |
||||
67 | * Store a newly created resource in storage. |
||||
68 | * |
||||
69 | * @param \Illuminate\Http\Request $request |
||||
70 | * @return \Illuminate\Http\Response |
||||
71 | */ |
||||
72 | public function store(Request $request) |
||||
73 | { |
||||
74 | $request->validate([ |
||||
75 | 'sour' => 'required', |
||||
76 | 'auth' => 'required', |
||||
77 | 'name' => 'required', |
||||
78 | 'repository_id' => 'required', |
||||
79 | 'author_id' => 'required', |
||||
80 | 'publication_id' => 'required', |
||||
81 | 'type_id' => 'required', |
||||
82 | 'is_active' => 'required', |
||||
83 | |||||
84 | ]); |
||||
85 | |||||
86 | return Source::create([ |
||||
0 ignored issues
–
show
|
|||||
87 | 'sour' => $request->sour, |
||||
88 | 'titl' => $request->titl, |
||||
89 | 'auth' => $request->auth, |
||||
90 | 'data' => $request->data, |
||||
91 | 'text' => $request->text, |
||||
92 | 'publ' => $request->publ, |
||||
93 | 'abbr' => $request->abbr, |
||||
94 | 'name' => $request->name, |
||||
95 | 'description' => $request->description, |
||||
96 | 'repository_id' => $request->repository_id, |
||||
97 | 'author_id' => $request->author_id, |
||||
98 | 'publication_id' => $request->publication_id, |
||||
99 | 'type_id' => $request->type_id, |
||||
100 | 'is_active' => $request->is_active, |
||||
101 | 'group' => $request->group, |
||||
102 | 'quay' => $request->quay, |
||||
103 | 'page' => $request->page, |
||||
104 | ]); |
||||
105 | } |
||||
106 | |||||
107 | /** |
||||
108 | * Display the specified resource. |
||||
109 | * |
||||
110 | * @param int $id |
||||
111 | * @return \Illuminate\Http\Response |
||||
112 | */ |
||||
113 | public function show($id) |
||||
114 | { |
||||
115 | return Source::find($id); |
||||
0 ignored issues
–
show
|
|||||
116 | } |
||||
117 | |||||
118 | /** |
||||
119 | * Show the form for editing the specified resource. |
||||
120 | * |
||||
121 | * @param int $id |
||||
122 | * @return \Illuminate\Http\Response |
||||
123 | */ |
||||
124 | 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. ![]() |
|||||
125 | { |
||||
126 | // |
||||
127 | } |
||||
128 | |||||
129 | /** |
||||
130 | * Update the specified resource in storage. |
||||
131 | * |
||||
132 | * @param \Illuminate\Http\Request $request |
||||
133 | * @param int $id |
||||
134 | * @return \Illuminate\Http\Response |
||||
135 | */ |
||||
136 | public function update(Request $request, $id) |
||||
137 | { |
||||
138 | $request->validate([ |
||||
139 | 'sour' => 'required', |
||||
140 | 'auth' => 'required', |
||||
141 | 'name' => 'required', |
||||
142 | 'repository_id' => 'required', |
||||
143 | 'author_id' => 'required', |
||||
144 | 'publication_id' => 'required', |
||||
145 | 'type_id' => 'required', |
||||
146 | 'is_active' => 'required', |
||||
147 | |||||
148 | ]); |
||||
149 | |||||
150 | $source = Source::find($id); |
||||
151 | $source->sour = $request->sour; |
||||
152 | $source->titl = $request->titl; |
||||
153 | $source->auth = $request->auth; |
||||
154 | $source->data = $request->data; |
||||
155 | $source->text = $request->text; |
||||
156 | $source->publ = $request->publ; |
||||
157 | $source->abbr = $request->abbr; |
||||
158 | $source->name = $request->name; |
||||
159 | $source->description = $request->description; |
||||
160 | $source->repository_id = $request->repository_id; |
||||
161 | $source->author_id = $request->author_id; |
||||
162 | $source->publication_id = $request->publication_id; |
||||
163 | $source->type_id = $request->type_id; |
||||
164 | $source->is_active = $request->is_active; |
||||
165 | $source->group = $request->group; |
||||
166 | $source->quay = $request->quay; |
||||
167 | $source->page = $request->page; |
||||
168 | $source->save(); |
||||
169 | |||||
170 | return $source; |
||||
0 ignored issues
–
show
|
|||||
171 | } |
||||
172 | |||||
173 | /** |
||||
174 | * Remove the specified resource from storage. |
||||
175 | * |
||||
176 | * @param int $id |
||||
177 | * @return \Illuminate\Http\Response |
||||
178 | */ |
||||
179 | public function destroy($id) |
||||
180 | { |
||||
181 | $source = Source::find($id); |
||||
182 | if ($source) { |
||||
183 | $source->delete(); |
||||
184 | |||||
185 | return 'true'; |
||||
0 ignored issues
–
show
|
|||||
186 | } |
||||
187 | |||||
188 | return 'false'; |
||||
0 ignored issues
–
show
|
|||||
189 | } |
||||
190 | |||||
191 | public function get() |
||||
192 | { |
||||
193 | $type_data = DB::table('types')->get(); |
||||
194 | |||||
195 | return $type_data; |
||||
196 | } |
||||
197 | } |
||||
198 |