-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckoutController.php
More file actions
87 lines (75 loc) · 2.21 KB
/
CheckoutController.php
File metadata and controls
87 lines (75 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace App\Http\Controllers;
use App\Models\Checkout;
use App\Http\Requests\StoreCheckoutRequest;
use App\Http\Requests\UpdateCheckoutRequest;
use App\Models\Event;
use App\Models\Ticket;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Auth;
use Ramsey\Uuid\Uuid;
class CheckoutController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreCheckoutRequest $request, string $event_uuid): JsonResponse
{
$args = $request->validated();
$event = Event::where('uuid', $event_uuid)
->firstOrFail();
$ticket = Ticket::where('event_id', $event->id)
->where('ticket_nonce', Uuid::fromString($args['ticket_code'])
->getBytes())
->where('asset_id', $args['asset_id'])
->withCount(['checkins', 'checkouts'])
->firstOrFail();
if ($ticket->checkins_count === $ticket->checkouts_count) {
// If the checkin count is less than or equal to the checkouts count
// then we can't very well add a new checkout can we?
return response()->json([
'message' => 'Ticket has not been checked in!'
], 400);
}
// Since we've arrive here it is probably safe to insert the "checkin"
// record now
$checkout = new Checkout();
$checkout->ticket()
->associate($ticket);
$checkout->user()
->associate(Auth::user());
$checkout->save();
$checkout->setVisible([
'id'
]);
return response()->json($checkout);
}
/**
* Display the specified resource.
*/
public function show(Checkout $checkout)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(UpdateCheckoutRequest $request, Checkout $checkout)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Checkout $checkout)
{
//
}
}