familytree365 /
backend
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Http\Controllers; |
||||
| 4 | |||||
| 5 | use App\Models\Citation; |
||||
| 6 | use Illuminate\Http\Request; |
||||
| 7 | |||||
| 8 | class CitationController 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 = Citation::query(); |
||||
| 18 | |||||
| 19 | if ($request->has('searchTerm')) { |
||||
| 20 | $columnsToSearch = ['name', 'description', 'date', 'is_active', 'volume', 'page', 'confidence', 'source_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
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 | 'name' => 'required', |
||||
| 72 | 'description' => 'required', |
||||
| 73 | 'volume' => 'required', |
||||
| 74 | 'page' => 'required', |
||||
| 75 | 'is_active' => 'required', |
||||
| 76 | 'confidence' => 'required', |
||||
| 77 | 'source_id' => 'required', |
||||
| 78 | ]); |
||||
| 79 | |||||
| 80 | return Citation::create([ |
||||
|
0 ignored issues
–
show
|
|||||
| 81 | 'name' => $request->name, |
||||
| 82 | 'description' => $request->description, |
||||
| 83 | 'date' => $request->date, |
||||
| 84 | 'volume' => $request->volume, |
||||
| 85 | 'page' => $request->page, |
||||
| 86 | 'is_active' => $request->is_active, |
||||
| 87 | 'confidence' => $request->confidence, |
||||
| 88 | 'source_id' => $request->source_id, |
||||
| 89 | ]); |
||||
| 90 | } |
||||
| 91 | |||||
| 92 | /** |
||||
| 93 | * Display the specified resource. |
||||
| 94 | * |
||||
| 95 | * @param int $id |
||||
| 96 | * @return \Illuminate\Http\Response |
||||
| 97 | */ |
||||
| 98 | public function show($id) |
||||
| 99 | { |
||||
| 100 | return Citation::find($id); |
||||
|
0 ignored issues
–
show
|
|||||
| 101 | } |
||||
| 102 | |||||
| 103 | /** |
||||
| 104 | * Show the form for editing the specified resource. |
||||
| 105 | * |
||||
| 106 | * @param int $id |
||||
| 107 | * @return \Illuminate\Http\Response |
||||
| 108 | */ |
||||
| 109 | 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...
|
|||||
| 110 | { |
||||
| 111 | // |
||||
| 112 | } |
||||
| 113 | |||||
| 114 | /** |
||||
| 115 | * Update the specified resource in storage. |
||||
| 116 | * |
||||
| 117 | * @param \Illuminate\Http\Request $request |
||||
| 118 | * @param int $id |
||||
| 119 | * @return \Illuminate\Http\Response |
||||
| 120 | */ |
||||
| 121 | public function update(Request $request, $id) |
||||
| 122 | { |
||||
| 123 | $request->validate([ |
||||
| 124 | 'name' => 'required', |
||||
| 125 | 'description' => 'required', |
||||
| 126 | 'volume' => 'required', |
||||
| 127 | 'page' => 'required', |
||||
| 128 | 'is_active' => 'required', |
||||
| 129 | 'confidence' => 'required', |
||||
| 130 | 'source_id' => 'required', |
||||
| 131 | ]); |
||||
| 132 | |||||
| 133 | $citation = Citation::find($id); |
||||
| 134 | $citation->name = $request->name; |
||||
| 135 | $citation->description = $request->description; |
||||
| 136 | $citation->date = $request->date; |
||||
| 137 | $citation->volume = $request->volume; |
||||
| 138 | $citation->page = $request->page; |
||||
| 139 | $citation->is_active = $request->is_active; |
||||
| 140 | $citation->confidence = $request->confidence; |
||||
| 141 | $citation->source_id = $request->source_id; |
||||
| 142 | $citation->save(); |
||||
| 143 | |||||
| 144 | return $citation; |
||||
|
0 ignored issues
–
show
|
|||||
| 145 | } |
||||
| 146 | |||||
| 147 | /** |
||||
| 148 | * Remove the specified resource from storage. |
||||
| 149 | * |
||||
| 150 | * @param int $id |
||||
| 151 | * @return \Illuminate\Http\Response |
||||
| 152 | */ |
||||
| 153 | public function destroy($id) |
||||
| 154 | { |
||||
| 155 | $citation = Citation::find($id); |
||||
| 156 | if ($citation) { |
||||
| 157 | $citation->delete(); |
||||
| 158 | |||||
| 159 | return 'true'; |
||||
|
0 ignored issues
–
show
|
|||||
| 160 | } |
||||
| 161 | |||||
| 162 | return 'false'; |
||||
|
0 ignored issues
–
show
|
|||||
| 163 | } |
||||
| 164 | } |
||||
| 165 |