Issues (465)

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

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Company;
6
use App\Models\Family;
7
use App\Models\FamilyEvent;
8
use App\Models\Place;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\DB;
11
12
class FamilyEventController extends Controller
13
{
14
    /**
15
     * Display a listing of the resource.
16
     *
17
     * @return \Illuminate\Http\Response
18
     */
19
    public function index(Request $request)
20
    {
21
        $query = FamilyEvent::query()->with(['family', 'place']);
22
23
        if ($request->has('searchTerm')) {
24
            $columnsToSearch = ['family_id', 'places_id', 'date', 'title', 'description', 'year', 'month', 'day', 'type', 'plac', 'phon', 'caus', 'age', 'agnc', 'husb', 'wife', 'converted_date', 'addr_id'];
25
            $search_term = json_decode($request->searchTerm)->searchTerm;
26
            if (! empty($search_term)) {
27
                $searchQuery = '%'.$search_term.'%';
28
                foreach ($columnsToSearch as $column) {
29
                    $query->orWhere($column, 'LIKE', $searchQuery);
30
                }
31
            }
32
        }
33
34
        if ($request->has('columnFilters')) {
35
            $filters = get_object_vars(json_decode($request->columnFilters));
36
37
            foreach ($filters as $key => $value) {
38
                if (! empty($value)) {
39
                    $query->orWhere($key, 'like', '%'.$value.'%');
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
The variable $rows does not seem to be defined for all execution paths leading up to this point.
Loading history...
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
    public function get()
67
    {
68
        $company = Company::all()->count();
69
70
        return $company;
71
    }
72
73
    /**
74
     * Store a newly created resource in storage.
75
     *
76
     * @param  \Illuminate\Http\Request  $request
77
     * @return \Illuminate\Http\Response
78
     */
79
    public function store(Request $request)
80
    {
81
        $request->validate([
82
            'family_id' => 'required',
83
            'places_id' => 'required',
84
            'date' => 'required',
85
            'title' => 'required',
86
            'description' => 'required',
87
            'year' => 'required',
88
            'month' => 'required',
89
            'day' => 'required',
90
            'type' => 'required',
91
            'plac' => 'required',
92
            'phon' => 'required',
93
            'caus' => 'required',
94
            'age' => 'required',
95
            // 'agnc' => 'required',
96
            'husb' => 'required',
97
            'wife' => 'required',
98
            // 'converted_date' => 'required',
99
            // 'addr_id' => 'required'
100
101
        ]);
102
103
        return FamilyEvent::create([
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Family...fe' => $request->wife)) also could return the type App\Models\FamilyEvent which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
104
            'family_id' => $request->family_id,
105
            'places_id' => $request->places_id,
106
            'date' => $request->date,
107
            'title' => $request->title,
108
            'description' => $request->description,
109
            'year' => $request->year,
110
            'month' => $request->month,
111
            'day' => $request->day,
112
            'type' => $request->type,
113
            'plac' => $request->plac,
114
            'phon' => $request->phon,
115
            'caus' => $request->caus,
116
            'age' => $request->age,
117
            // 'agnc' => $request->agnc,
118
            'husb' => $request->husb,
119
            'wife' => $request->wife,
120
            // 'converted_date' => $request->converted_date,
121
            // 'addr_id' => $request->addr_id
122
        ]);
123
    }
124
125
    /**
126
     * Display the specified resource.
127
     *
128
     * @param  int  $id
129
     * @return \Illuminate\Http\Response
130
     */
131
    public function show($id)
132
    {
133
        return FamilyEvent::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\FamilyEvent::find($id) also could return the type App\Models\FamilyEvent which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
134
    }
135
136
    /**
137
     * Show the form for editing the specified resource.
138
     *
139
     * @param  int  $id
140
     * @return \Illuminate\Http\Response
141
     */
142
    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

142
    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...
143
    {
144
        //
145
    }
146
147
    /**
148
     * Update the specified resource in storage.
149
     *
150
     * @param  \Illuminate\Http\Request  $request
151
     * @param  int  $id
152
     * @return \Illuminate\Http\Response
153
     */
154
    public function update(Request $request, $id)
155
    {
156
        $request->validate([
157
            'family_id' => 'required',
158
            'places_id' => 'required',
159
            'date' => 'required',
160
            'title' => 'required',
161
            'description' => 'required',
162
            'year' => 'required',
163
            'month' => 'required',
164
            'day' => 'required',
165
            'type' => 'required',
166
            'plac' => 'required',
167
            'phon' => 'required',
168
            'caus' => 'required',
169
            'age' => 'required',
170
            // 'agnc' => 'required',
171
            'husb' => 'required',
172
            'wife' => 'required',
173
            // 'converted_date' => 'required',
174
            // 'addr_id' => 'required'
175
176
        ]);
177
178
        $familyevent = FamilyEvent::find($id);
179
        $familyevent->family_id = $request->family_id;
180
        $familyevent->places_id = $request->places_id;
181
        $familyevent->date = $request->date;
182
        $familyevent->title = $request->title;
183
        $familyevent->description = $request->description;
184
        $familyevent->year = $request->year;
185
        $familyevent->month = $request->month;
186
        $familyevent->day = $request->day;
187
        $familyevent->type = $request->type;
188
        $familyevent->plac = $request->plac;
189
        $familyevent->phon = $request->phon;
190
        $familyevent->caus = $request->caus;
191
        $familyevent->age = $request->age;
192
        $familyevent->agnc = $request->agnc;
193
        $familyevent->husb = $request->husb;
194
        $familyevent->wife = $request->wife;
195
        $familyevent->converted_date = $request->converted_date;
196
        $familyevent->addr_id = $request->addr_id;
197
        $familyevent->save();
198
199
        return $familyevent;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $familyevent also could return the type App\Models\FamilyEvent which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
200
    }
201
202
    /**
203
     * Remove the specified resource from storage.
204
     *
205
     * @param  int  $id
206
     * @return \Illuminate\Http\Response
207
     */
208
    public function destroy($id)
209
    {
210
        $familyevent = FamilyEvent::find($id);
211
        if ($familyevent) {
212
            $familyevent->delete();
213
214
            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...
215
        }
216
217
        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...
218
    }
219
}
220