Issues (465)

app/Http/Controllers/PersonEventController.php (7 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\PersonEvent;
6
use Illuminate\Http\Request;
7
8
class PersonEventController 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 = PersonEvent::query();
18
19
        if ($request->has('searchTerm')) {
20
            $columnsToSearch = ['converted_date', 'year', 'month', 'day', 'type', 'attr', 'plac', 'addr_id', 'phon', 'caus', 'age', 'agnc', 'adop', 'adop_famc', 'person_id', 'title', 'date', 'description', 'places_id'];
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
The variable $rows does not seem to be defined for all execution paths leading up to this point.
Loading history...
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
            // 'converted_date' => 'required',
72
            'person_id' => 'required',
73
            // 'title' => 'required',
74
            // 'type' => 'required',
75
            // 'attr' => 'required',
76
            'date' => 'required',
77
            'plac' => 'required',
78
            // 'addr_id' => 'required',
79
            'phon' => 'required',
80
            // 'caus' => 'required',
81
            // 'age' => 'required',
82
            // 'agnc' => 'required',
83
            // 'adop' => 'required',
84
            // 'places_id' => 'required',
85
            // 'description' => 'required',
86
            // 'adop_famc' => 'required',
87
            // 'year' => 'required',
88
            // 'month' => 'required',
89
            // 'day' => 'required'
90
        ]);
91
92
        return PersonEvent::create([
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Person...day' => $request->day)) also could return the type App\Models\PersonEvent which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
93
            'converted_date' => $request->converted_date,
94
            'person_id' => $request->person_id,
95
            'title' => $request->title,
96
            'type' => $request->type,
97
            'attr' => $request->attr,
98
            'date' => $request->date,
99
            'plac' => $request->plac,
100
            'phon' => $request->phon,
101
            'caus' => $request->caus,
102
            'age' => $request->age,
103
            'agnc' => $request->agnc,
104
            'adop' => $request->adop,
105
            'places_id' => $request->places_id,
106
            'description' => $request->description,
107
            'adop_famc' => $request->adop_famc,
108
            'year' => $request->year,
109
            'month' => $request->month,
110
            'day' => $request->day,
111
        ]);
112
    }
113
114
    /**
115
     * Display the specified resource.
116
     *
117
     * @param  int  $id
118
     * @return \Illuminate\Http\Response
119
     */
120
    public function show($id)
121
    {
122
        return PersonEvent::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\PersonEvent::find($id) also could return the type App\Models\PersonEvent which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
123
    }
124
125
    /**
126
     * Show the form for editing the specified resource.
127
     *
128
     * @param  int  $id
129
     * @return \Illuminate\Http\Response
130
     */
131
    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 ignore-unused  annotation

131
    public function edit(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
132
    {
133
        //
134
    }
135
136
    /**
137
     * Update the specified resource in storage.
138
     *
139
     * @param  \Illuminate\Http\Request  $request
140
     * @param  int  $id
141
     * @return \Illuminate\Http\Response
142
     */
143
    public function update(Request $request, $id)
144
    {
145
        $request->validate([
146
            // 'converted_date' => 'required',
147
            'person_id' => 'required',
148
            // 'title' => 'required',
149
            // 'type' => 'required',
150
            // 'attr' => 'required',
151
            'date' => 'required',
152
            'plac' => 'required',
153
            // 'addr_id' => 'required',
154
            'phon' => 'required',
155
            // 'caus' => 'required',
156
            // 'age' => 'required',
157
            // 'agnc' => 'required',
158
            // 'adop' => 'required',
159
            // 'places_id' => 'required',
160
            // 'description' => 'required',
161
            // 'adop_famc' => 'required',
162
            // 'year' => 'required',
163
            // 'month' => 'required',
164
            // 'day' => 'required'
165
        ]);
166
167
        $personevent = PersonEvent::find($id);
168
        $personevent->converted_date = $request->converted_date;
169
        $personevent->person_id = $request->person_id;
170
        $personevent->title = $request->title;
171
        $personevent->type = $request->type;
172
        $personevent->attr = $request->attr;
173
        $personevent->date = $request->date;
174
        $personevent->plac = $request->plac;
175
        $personevent->addr_id = $request->addr_id;
176
        $personevent->phon = $request->phon;
177
        $personevent->caus = $request->caus;
178
        $personevent->age = $request->age;
179
        $personevent->agnc = $request->agnc;
180
        $personevent->adop = $request->adop;
181
        $personevent->places_id = $request->places_id;
182
        $personevent->description = $request->description;
183
        $personevent->adop_famc = $request->adop_famc;
184
        $personevent->year = $request->year;
185
        $personevent->month = $request->month;
186
        $personevent->day = $request->day;
187
        $personevent->save();
188
189
        return $personevent;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $personevent also could return the type App\Models\PersonEvent which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
190
    }
191
192
    /**
193
     * Remove the specified resource from storage.
194
     *
195
     * @param  int  $id
196
     * @return \Illuminate\Http\Response
197
     */
198
    public function destroy($id)
199
    {
200
        $personevent = PersonEvent::find($id);
201
        if ($personevent) {
202
            $personevent->delete();
203
204
            return 'true';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'true' returns the type string which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
205
        }
206
207
        return 'false';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'false' returns the type string which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
208
    }
209
}
210