Issues (465)

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

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\PersonNameFone;
6
use Illuminate\Http\Request;
7
8
class PersonNameFoneController 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 = PersonNameFone::query();
18
19
        if ($request->has('searchTerm')) {
20
            $columnsToSearch = ['name', 'email', 'phone'];
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
            'group' => 'required',
72
            'gid' => 'required',
73
            'type' => 'required',
74
            'name' => 'required',
75
            'npfx' => 'required',
76
            'givn' => 'required',
77
            'nick' => 'required',
78
            'spfx' => 'required',
79
            'surn' => 'required',
80
            'nsfx' => 'required',
81
        ]);
82
83
        return PersonNameFone::create([
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Person...fx' => $request->nsfx)) also could return the type App\Models\PersonNameFone which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
84
            'group' => $request->group,
85
            'gid' => $request->gid,
86
            'type' => $request->type,
87
            'name' => $request->name,
88
            'npfx' => $request->npfx,
89
            'givn' => $request->givn,
90
            'nick' => $request->nick,
91
            'spfx' => $request->spfx,
92
            'surn' => $request->surn,
93
            'nsfx' => $request->nsfx,
94
        ]);
95
    }
96
97
    /**
98
     * Display the specified resource.
99
     *
100
     * @param  int  $id
101
     * @return \Illuminate\Http\Response
102
     */
103
    public function show($id)
104
    {
105
        return PersonNameFone::find($id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\PersonNameFone::find($id) also could return the type App\Models\PersonNameFone which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
106
    }
107
108
    /**
109
     * Show the form for editing the specified resource.
110
     *
111
     * @param  int  $id
112
     * @return \Illuminate\Http\Response
113
     */
114
    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

114
    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...
115
    {
116
        //
117
    }
118
119
    /**
120
     * Update the specified resource in storage.
121
     *
122
     * @param  \Illuminate\Http\Request  $request
123
     * @param  int  $id
124
     * @return \Illuminate\Http\Response
125
     */
126
    public function update(Request $request, $id)
127
    {
128
        $request->validate([
129
            'group' => 'required',
130
            'gid' => 'required',
131
            'type' => 'required',
132
            'name' => 'required',
133
            'npfx' => 'required',
134
            'givn' => 'required',
135
            'nick' => 'required',
136
            'spfx' => 'required',
137
            'surn' => 'required',
138
            'nsfx' => 'required',
139
        ]);
140
141
        $personnamefone = PersonNameFone::find($id);
142
        $personnamefone->group = $request->group;
143
        $personnamefone->gid = $request->gid;
144
        $personnamefone->type = $request->type;
145
        $personnamefone->name = $request->name;
146
        $personnamefone->npfx = $request->npfx;
147
        $personnamefone->givn = $request->givn;
148
        $personnamefone->nick = $request->nick;
149
        $personnamefone->spfx = $request->spfx;
150
        $personnamefone->surn = $request->surn;
151
        $personnamefone->nsfx = $request->nsfx;
152
        $personnamefone->save();
153
154
        return $personnamefone;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $personnamefone also could return the type App\Models\PersonNameFone which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
155
    }
156
157
    /**
158
     * Remove the specified resource from storage.
159
     *
160
     * @param  int  $id
161
     * @return \Illuminate\Http\Response
162
     */
163
    public function destroy($id)
164
    {
165
        $personnamefonefone = PersonNameFone::find($id);
166
        if ($personnamefonefone) {
167
            $personnamefonefone->delete();
168
169
            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...
170
        }
171
172
        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...
173
    }
174
}
175