familytree365 /
backend
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Http\Controllers; |
||||
| 4 | |||||
| 5 | use App\Models\Person; |
||||
| 6 | use Illuminate\Http\Request; |
||||
| 7 | |||||
| 8 | class PersonController 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 = Person::query(); |
||||
| 18 | |||||
| 19 | if ($request->has('searchTerm')) { |
||||
| 20 | $columnsToSearch = ['title', 'name', 'appellative', 'uid', 'email', 'phone', 'birthday', 'deathday', 'bank', 'bank_account', 'obs', 'givn', 'surn', 'type', 'npfx', 'nick', 'spfx', 'nsfx', 'secx', 'description', 'child_in_family_id', 'chan', 'rin', 'resn', 'rfn', 'afn']; |
||||
| 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 | if (! count($request->all())) { |
||||
| 49 | $rows = $query->get()->toArray(); |
||||
| 50 | } |
||||
| 51 | |||||
| 52 | return $rows; |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||||
| 53 | } |
||||
| 54 | |||||
| 55 | /** |
||||
| 56 | * Show the form for creating a new resource. |
||||
| 57 | * |
||||
| 58 | * @return \Illuminate\Http\Response |
||||
| 59 | */ |
||||
| 60 | public function create() |
||||
| 61 | { |
||||
| 62 | // |
||||
| 63 | } |
||||
| 64 | |||||
| 65 | /** |
||||
| 66 | * Store a newly created resource in storage. |
||||
| 67 | * |
||||
| 68 | * @param \Illuminate\Http\Request $request |
||||
| 69 | * @return \Illuminate\Http\Response |
||||
| 70 | */ |
||||
| 71 | public function store(Request $request) |
||||
| 72 | { |
||||
| 73 | $request->validate([ |
||||
| 74 | 'name' => 'required', |
||||
| 75 | ]); |
||||
| 76 | |||||
| 77 | $person = new Person(); |
||||
| 78 | $person->title = $request->title; |
||||
|
0 ignored issues
–
show
|
|||||
| 79 | $person->name = $request->name; |
||||
|
0 ignored issues
–
show
|
|||||
| 80 | $person->appellative = $request->appellative; |
||||
|
0 ignored issues
–
show
|
|||||
| 81 | $person->uid = $request->uid; |
||||
|
0 ignored issues
–
show
|
|||||
| 82 | $person->email = $request->email; |
||||
|
0 ignored issues
–
show
|
|||||
| 83 | $person->phone = $request->phone; |
||||
|
0 ignored issues
–
show
|
|||||
| 84 | $person->birthday = $request->birthday; |
||||
|
0 ignored issues
–
show
|
|||||
| 85 | $person->deathday = $request->deathday; |
||||
|
0 ignored issues
–
show
|
|||||
| 86 | $person->bank = $request->bank; |
||||
|
0 ignored issues
–
show
|
|||||
| 87 | $person->bank_account = $request->bank_account; |
||||
|
0 ignored issues
–
show
|
|||||
| 88 | $person->obs = $request->obs; |
||||
|
0 ignored issues
–
show
|
|||||
| 89 | $person->givn = $request->givn; |
||||
|
0 ignored issues
–
show
|
|||||
| 90 | $person->surn = $request->surn; |
||||
|
0 ignored issues
–
show
|
|||||
| 91 | $person->type = $request->type; |
||||
|
0 ignored issues
–
show
|
|||||
| 92 | $person->npfx = $request->npfx; |
||||
|
0 ignored issues
–
show
|
|||||
| 93 | $person->nick = $request->nick; |
||||
|
0 ignored issues
–
show
|
|||||
| 94 | $person->spfx = $request->spfx; |
||||
|
0 ignored issues
–
show
|
|||||
| 95 | $person->nsfx = $request->nsfx; |
||||
|
0 ignored issues
–
show
|
|||||
| 96 | $person->sex = $request->sex; |
||||
|
0 ignored issues
–
show
|
|||||
| 97 | $person->description = $request->description; |
||||
|
0 ignored issues
–
show
|
|||||
| 98 | $person->child_in_family_id = $request->child_in_family_id; |
||||
|
0 ignored issues
–
show
|
|||||
| 99 | $person->chan = $request->chan; |
||||
|
0 ignored issues
–
show
|
|||||
| 100 | $person->rin = $request->rin; |
||||
|
0 ignored issues
–
show
|
|||||
| 101 | $person->resn = $request->resn; |
||||
|
0 ignored issues
–
show
|
|||||
| 102 | $person->rfn = $request->rfn; |
||||
|
0 ignored issues
–
show
|
|||||
| 103 | $person->afn = $request->afn; |
||||
|
0 ignored issues
–
show
|
|||||
| 104 | $person->save(); |
||||
| 105 | |||||
| 106 | return $person; |
||||
|
0 ignored issues
–
show
|
|||||
| 107 | } |
||||
| 108 | |||||
| 109 | /** |
||||
| 110 | * Display the specified resource. |
||||
| 111 | * |
||||
| 112 | * @param int $id |
||||
| 113 | * @return \Illuminate\Http\Response |
||||
| 114 | */ |
||||
| 115 | public function show($id) |
||||
| 116 | { |
||||
| 117 | return Person::find($id); |
||||
|
0 ignored issues
–
show
|
|||||
| 118 | } |
||||
| 119 | |||||
| 120 | /** |
||||
| 121 | * Show the form for editing the specified resource. |
||||
| 122 | * |
||||
| 123 | * @param int $id |
||||
| 124 | * @return \Illuminate\Http\Response |
||||
| 125 | */ |
||||
| 126 | 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. Loading history...
|
|||||
| 127 | { |
||||
| 128 | // |
||||
| 129 | } |
||||
| 130 | |||||
| 131 | /** |
||||
| 132 | * Update the specified resource in storage. |
||||
| 133 | * |
||||
| 134 | * @param \Illuminate\Http\Request $request |
||||
| 135 | * @param int $id |
||||
| 136 | * @return \Illuminate\Http\Response |
||||
| 137 | */ |
||||
| 138 | public function update(Request $request, $id) |
||||
| 139 | { |
||||
| 140 | $request->validate([ |
||||
| 141 | 'name' => 'required', |
||||
| 142 | ]); |
||||
| 143 | |||||
| 144 | $person = Person::find($id); |
||||
| 145 | $person->title = $request->title; |
||||
|
0 ignored issues
–
show
|
|||||
| 146 | $person->name = $request->name; |
||||
|
0 ignored issues
–
show
|
|||||
| 147 | $person->appellative = $request->appellative; |
||||
|
0 ignored issues
–
show
|
|||||
| 148 | $person->uid = $request->uid; |
||||
|
0 ignored issues
–
show
|
|||||
| 149 | $person->email = $request->email; |
||||
|
0 ignored issues
–
show
|
|||||
| 150 | $person->phone = $request->phone; |
||||
|
0 ignored issues
–
show
|
|||||
| 151 | $person->birthday = $request->birthday; |
||||
|
0 ignored issues
–
show
|
|||||
| 152 | $person->deathday = $request->deathday; |
||||
|
0 ignored issues
–
show
|
|||||
| 153 | $person->bank = $request->bank; |
||||
|
0 ignored issues
–
show
|
|||||
| 154 | $person->bank_account = $request->bank_account; |
||||
|
0 ignored issues
–
show
|
|||||
| 155 | $person->obs = $request->obs; |
||||
|
0 ignored issues
–
show
|
|||||
| 156 | $person->givn = $request->givn; |
||||
|
0 ignored issues
–
show
|
|||||
| 157 | $person->surn = $request->surn; |
||||
|
0 ignored issues
–
show
|
|||||
| 158 | $person->type = $request->type; |
||||
|
0 ignored issues
–
show
|
|||||
| 159 | $person->npfx = $request->npfx; |
||||
|
0 ignored issues
–
show
|
|||||
| 160 | $person->nick = $request->nick; |
||||
|
0 ignored issues
–
show
|
|||||
| 161 | $person->spfx = $request->spfx; |
||||
|
0 ignored issues
–
show
|
|||||
| 162 | $person->nsfx = $request->nsfx; |
||||
|
0 ignored issues
–
show
|
|||||
| 163 | $person->sex = $request->sex; |
||||
|
0 ignored issues
–
show
|
|||||
| 164 | $person->description = $request->description; |
||||
|
0 ignored issues
–
show
|
|||||
| 165 | $person->child_in_family_id = $request->child_in_family_id; |
||||
|
0 ignored issues
–
show
|
|||||
| 166 | $person->chan = $request->chan; |
||||
|
0 ignored issues
–
show
|
|||||
| 167 | $person->rin = $request->rin; |
||||
|
0 ignored issues
–
show
|
|||||
| 168 | $person->resn = $request->resn; |
||||
|
0 ignored issues
–
show
|
|||||
| 169 | $person->rfn = $request->rfn; |
||||
|
0 ignored issues
–
show
|
|||||
| 170 | $person->afn = $request->afn; |
||||
|
0 ignored issues
–
show
|
|||||
| 171 | $person->save(); |
||||
| 172 | |||||
| 173 | return $person; |
||||
|
0 ignored issues
–
show
|
|||||
| 174 | } |
||||
| 175 | |||||
| 176 | /** |
||||
| 177 | * Remove the specified resource from storage. |
||||
| 178 | * |
||||
| 179 | * @param int $id |
||||
| 180 | * @return \Illuminate\Http\Response |
||||
| 181 | */ |
||||
| 182 | public function destroy($id) |
||||
| 183 | { |
||||
| 184 | $person = Person::find($id); |
||||
| 185 | if ($person) { |
||||
| 186 | $person->delete(); |
||||
| 187 | |||||
| 188 | return 'true'; |
||||
|
0 ignored issues
–
show
|
|||||
| 189 | } |
||||
| 190 | |||||
| 191 | return 'false'; |
||||
|
0 ignored issues
–
show
|
|||||
| 192 | } |
||||
| 193 | } |
||||
| 194 |