1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Models\Repository; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
|
8
|
|
|
class RepositoryController 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 = Repository::query()->with(['type', 'addr']); |
18
|
|
|
|
19
|
|
|
if ($request->has('searchTerm')) { |
20
|
|
|
$columnsToSearch = ['repo', 'name', 'addr_id', 'rin', 'email', 'phon', 'fax', 'www', 'description', 'type_id', 'is_active']; |
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
|
|
|
$relationship_column = ['addr.adr1', 'type.name']; |
33
|
|
|
foreach ($filters as $key => $value) { |
34
|
|
|
if (! in_array($key, $relationship_column)) { |
35
|
|
|
if (! empty($value)) { |
36
|
|
|
$query->orWhere($key, 'like', '%'.$value.'%'); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ($request->has('sort.0')) { |
43
|
|
|
$sort = json_decode($request->sort[0]); |
44
|
|
|
$query->orderBy($sort->field, $sort->type); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if ($request->has('perPage')) { |
48
|
|
|
$rows = $query->paginate($request->perPage); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $rows; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Show the form for creating a new resource. |
56
|
|
|
* |
57
|
|
|
* @return \Illuminate\Http\Response |
58
|
|
|
*/ |
59
|
|
|
public function create() |
60
|
|
|
{ |
61
|
|
|
// |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Store a newly created resource in storage. |
66
|
|
|
* |
67
|
|
|
* @param \Illuminate\Http\Request $request |
68
|
|
|
* @return \Illuminate\Http\Response |
69
|
|
|
*/ |
70
|
|
|
public function store(Request $request) |
71
|
|
|
{ |
72
|
|
|
$request->validate([ |
73
|
|
|
'repo' => 'required', |
74
|
|
|
'addr_id' => 'required', |
75
|
|
|
'phon' => 'required', |
76
|
|
|
'email' => 'required', |
77
|
|
|
'name' => 'required', |
78
|
|
|
'type_id' => 'required', |
79
|
|
|
'is_active' => 'required', |
80
|
|
|
]); |
81
|
|
|
|
82
|
|
|
return Repository::create([ |
|
|
|
|
83
|
|
|
'repo' => $request->repo, |
84
|
|
|
'addr_id' => $request->addr_id, |
85
|
|
|
'rin' => $request->rin, |
86
|
|
|
'phon' => $request->phon, |
87
|
|
|
'email' => $request->email, |
88
|
|
|
'fax' => $request->fax, |
89
|
|
|
'www' => $request->www, |
90
|
|
|
'name' => $request->name, |
91
|
|
|
'is_active' => $request->is_active, |
92
|
|
|
'description' => $request->description, |
93
|
|
|
]); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Display the specified resource. |
98
|
|
|
* |
99
|
|
|
* @param int $id |
100
|
|
|
* @return \Illuminate\Http\Response |
101
|
|
|
*/ |
102
|
|
|
public function show($id) |
103
|
|
|
{ |
104
|
|
|
return Repository::find($id); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Show the form for editing the specified resource. |
109
|
|
|
* |
110
|
|
|
* @param int $id |
111
|
|
|
* @return \Illuminate\Http\Response |
112
|
|
|
*/ |
113
|
|
|
public function edit($id) |
|
|
|
|
114
|
|
|
{ |
115
|
|
|
// |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Update the specified resource in storage. |
120
|
|
|
* |
121
|
|
|
* @param \Illuminate\Http\Request $request |
122
|
|
|
* @param int $id |
123
|
|
|
* @return \Illuminate\Http\Response |
124
|
|
|
*/ |
125
|
|
|
public function update(Request $request, $id) |
126
|
|
|
{ |
127
|
|
|
$request->validate([ |
128
|
|
|
'repo' => 'required', |
129
|
|
|
'addr_id' => 'required', |
130
|
|
|
'phon' => 'required', |
131
|
|
|
'email' => 'required', |
132
|
|
|
'name' => 'required', |
133
|
|
|
'type_id' => 'required', |
134
|
|
|
'is_active' => 'required', |
135
|
|
|
]); |
136
|
|
|
|
137
|
|
|
$repository = Repository::find($id); |
138
|
|
|
$repository->repo = $request->repo; |
139
|
|
|
$repository->addr_id = $request->addr_id; |
140
|
|
|
$repository->rin = $request->rin; |
141
|
|
|
$repository->phon = $request->phon; |
142
|
|
|
$repository->email = $request->email; |
143
|
|
|
$repository->fax = $request->fax; |
144
|
|
|
$repository->www = $request->www; |
145
|
|
|
$repository->name = $request->name; |
146
|
|
|
$repository->is_active = $request->is_active; |
147
|
|
|
$repository->description = $request->description; |
148
|
|
|
$repository->save(); |
149
|
|
|
|
150
|
|
|
return $repository; |
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Remove the specified resource from storage. |
155
|
|
|
* |
156
|
|
|
* @param int $id |
157
|
|
|
* @return \Illuminate\Http\Response |
158
|
|
|
*/ |
159
|
|
|
public function destroy($id) |
160
|
|
|
{ |
161
|
|
|
$repository = Repository::find($id); |
162
|
|
|
if ($repository) { |
163
|
|
|
$repository->delete(); |
164
|
|
|
|
165
|
|
|
return 'true'; |
|
|
|
|
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return 'false'; |
|
|
|
|
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function get() |
172
|
|
|
{ |
173
|
|
|
$repo_data = Repository::all(); |
174
|
|
|
|
175
|
|
|
return $repo_data; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|