Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Commit

Permalink
feat: guest search
Browse files Browse the repository at this point in the history
  • Loading branch information
Takeno-hito committed Apr 8, 2021
1 parent 34a86f8 commit 5faaf85
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/Http/Controllers/GuestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,31 @@ public function show(Request $request, $id) {
return response()->json(new GuestResource($guest));
}

public function index() {
return response()->json(GuestResource::collection(Guest::all()));
public function index(Request $request) {
$query = $this->validate($request, [
'id' => ['string'],
'timestamp' => ['string'],
'guest_id' => ['string'],
'exh_id' => ['string'],
'reservation_id' => ['string'],
'log_type' => ['string'],
]);

$guests = Guest::query();

foreach ($query as $i => $value) {
if ($i == 'reservation_id') {
if ($request->user()->hasPermission('reservation')) {
abort(403);
}
if ($reservation = Reservation::find($value)) {
$guests->where('guest_id', $reservation->guest->id);
} else return response([]);
}
$guests->where($i, $value);
}

return response(GuestResource::collection($guests->get()));
}

public function enter(Request $request) {
Expand Down

0 comments on commit 5faaf85

Please sign in to comment.