1 | <?php |
||||
2 | |||||
3 | namespace App\Http\Controllers; |
||||
4 | |||||
5 | use App\Models\MediaObject; |
||||
6 | use App\Models\MediaObjectFile; |
||||
7 | use Illuminate\Http\Request; |
||||
8 | |||||
9 | class MediaObjectController 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 = MediaObject::query(); |
||||
19 | |||||
20 | if ($request->has('searchTerm')) { |
||||
21 | $columnsToSearch = ['group', 'titl', 'obje_id', 'rin']; |
||||
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 | |||||
34 | foreach ($filters as $key => $value) { |
||||
35 | if (! empty($value)) { |
||||
36 | $query->orWhere($key, 'like', '%'.$value.'%'); |
||||
37 | } |
||||
38 | } |
||||
39 | } |
||||
40 | |||||
41 | if ($request->has('sort.0')) { |
||||
42 | $sort = json_decode($request->sort[0]); |
||||
43 | $query->orderBy($sort->field, $sort->type); |
||||
44 | } |
||||
45 | |||||
46 | if ($request->has('perPage')) { |
||||
47 | $rows = $query->paginate($request->perPage); |
||||
48 | } |
||||
49 | |||||
50 | return $rows; |
||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() |
|||||
51 | } |
||||
52 | |||||
53 | /** |
||||
54 | * Show the form for creating a new resource. |
||||
55 | * |
||||
56 | * @return \Illuminate\Http\Response |
||||
57 | */ |
||||
58 | public function create() |
||||
59 | { |
||||
60 | // |
||||
61 | } |
||||
62 | |||||
63 | /** |
||||
64 | * Store a newly created resource in storage. |
||||
65 | * |
||||
66 | * @param \Illuminate\Http\Request $request |
||||
67 | * @return \Illuminate\Http\Response |
||||
68 | */ |
||||
69 | public function store(Request $request) |
||||
70 | { |
||||
71 | $request->validate([ |
||||
72 | 'titl' => 'required', |
||||
73 | ]); |
||||
74 | |||||
75 | return MediaObject::create([ |
||||
0 ignored issues
–
show
|
|||||
76 | 'group' => $request->group, |
||||
77 | 'titl' => $request->titl, |
||||
78 | 'obje_id' => $request->obje_id, |
||||
79 | 'rin' => $request->rin, |
||||
80 | ]); |
||||
81 | } |
||||
82 | |||||
83 | /** |
||||
84 | * Display the specified resource. |
||||
85 | * |
||||
86 | * @param int $id |
||||
87 | * @return \Illuminate\Http\Response |
||||
88 | */ |
||||
89 | public function show($id) |
||||
90 | { |
||||
91 | return MediaObject::find($id); |
||||
0 ignored issues
–
show
|
|||||
92 | } |
||||
93 | |||||
94 | /** |
||||
95 | * Show the form for editing the specified resource. |
||||
96 | * |
||||
97 | * @param int $id |
||||
98 | * @return \Illuminate\Http\Response |
||||
99 | */ |
||||
100 | 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. ![]() |
|||||
101 | { |
||||
102 | // |
||||
103 | } |
||||
104 | |||||
105 | /** |
||||
106 | * Update the specified resource in storage. |
||||
107 | * |
||||
108 | * @param \Illuminate\Http\Request $request |
||||
109 | * @param int $id |
||||
110 | * @return \Illuminate\Http\Response |
||||
111 | */ |
||||
112 | public function update(Request $request, $id) |
||||
113 | { |
||||
114 | $request->validate([ |
||||
115 | 'titl' => 'required', |
||||
116 | ]); |
||||
117 | |||||
118 | $mediaobject = MediaObject::find($id); |
||||
119 | $mediaobject->group = $request->group; |
||||
120 | $mediaobject->titl = $request->titl; |
||||
121 | $mediaobject->obje_id = $request->obje_id; |
||||
122 | $mediaobject->rin = $request->rin; |
||||
123 | $mediaobject->save(); |
||||
124 | |||||
125 | return $mediaobject; |
||||
0 ignored issues
–
show
|
|||||
126 | } |
||||
127 | |||||
128 | /** |
||||
129 | * Remove the specified resource from storage. |
||||
130 | * |
||||
131 | * @param int $id |
||||
132 | * @return \Illuminate\Http\Response |
||||
133 | */ |
||||
134 | public function destroy($id) |
||||
135 | { |
||||
136 | $mediaobject = MediaObject::find($id); |
||||
137 | if ($mediaobject) { |
||||
138 | $mediaobject->delete(); |
||||
139 | |||||
140 | return 'true'; |
||||
0 ignored issues
–
show
|
|||||
141 | } |
||||
142 | |||||
143 | return 'false'; |
||||
0 ignored issues
–
show
|
|||||
144 | } |
||||
145 | } |
||||
146 |