public function store(StoreIssueBook $request)
{
$validated = $request->validated();
$count_not_returned = IssueBook::where('client_id', $validated['client_id'])->where('is_returned', $validated['is_returned'])->count();
if ($count_not_returned >= 2) {
return response()->json(['status' => 0, 'message' => 'Client has already issued a 2 books'], 400);
}
$count_unique = IssueBook::where('client_id', $validated['client_id'])->where('book_id', $validated['book_id'])->count();
if ($count_unique) {
return response()->json(['status' => 0, 'message' => 'Book is already issued to this client'], 400);
}
$issueBook = IssueBook::create($validated);
return response()->json(['data' => $issueBook], 201);
}